V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
RangerWolf
V2EX  ›  Python

[求助]Celery 的定时任务,为什么看到定时执行的情况,但是感觉没有执行?

  •  
  •   RangerWolf · 2015-03-12 18:12:39 +08:00 · 6506 次点击
    这是一个创建于 3334 天前的主题,其中的信息可能已经有所发展或是发生改变。
    今天刚试用Celery。worker的模式已经正常,但是在beat 模式下,虽然看到每隔10秒就执行一次的记录,但是感觉task没有被执行。

    @celery.task
    def add(x, y):
    str="a string to print to file"
    f=open('out.txt','a')
    print >>f,str
    f.close()

    上面是我的定义的task
    在beat模式下面没看到有新的str输出到out.txt之中~

    搞了很久也没搞定,哪位懂的能来帮忙看看吗?

    对于定时任务,参考的是 http://www.metaltoad.com/blog/celery-periodic-tasks-installation-infinity

    已google过,搞不定,有点想奔溃了。。。
    第 1 条附言  ·  2015-03-13 22:43:24 +08:00
    根据一步步的经验,写了一个入门文档,希望对后面新手有帮助。
    另外这些经验也是在乱糟糟的搞了好几遍之后再凭记忆整理出来的,有错误的话还请轻拍
    第 2 条附言  ·  2015-03-13 22:43:48 +08:00
    12 条回复    2015-03-13 22:41:41 +08:00
    weyou
        1
    weyou  
       2015-03-12 19:07:03 +08:00   ❤️ 1
    redis server有启动吗?
    dongweiming
        2
    dongweiming  
       2015-03-12 21:56:52 +08:00   ❤️ 1
    @RangerWolf 没有问题啊. 把你的celeryconfig.py和task.py粘出来吧
    dongweiming
        3
    dongweiming  
       2015-03-12 21:59:18 +08:00
    还有你的启动命令
    kunimi
        4
    kunimi  
       2015-03-12 22:05:47 +08:00   ❤️ 1
    估计有很大可能是只启动了beat而没有同时启动worker,贴具体步骤吧。
    Archangel_SDY
        5
    Archangel_SDY  
       2015-03-12 23:06:12 +08:00   ❤️ 1
    如果你用 RabbitMQ, 要保证至少有 100M 的磁盘空间, 上次被这个坑了好久.
    RangerWolf
        6
    RangerWolf  
    OP
       2015-03-13 07:38:17 +08:00
    @weyou 有的~ 已经启动而且显示客户端链接数之类的
    RangerWolf
        7
    RangerWolf  
    OP
       2015-03-13 07:38:54 +08:00
    @RangerWolf 用的redis做broker,mysql做backend。 磁盘空间也够,还有不到10G空间吧
    RangerWolf
        8
    RangerWolf  
    OP
       2015-03-13 07:39:07 +08:00
    @Archangel_SDY 用的redis做broker,mysql做backend。 磁盘空间也够,还有不到10G空间吧
    RangerWolf
        9
    RangerWolf  
    OP
       2015-03-13 07:39:51 +08:00
    @kunimi 目前就1个task。。。 应该不大啊
    RangerWolf
        10
    RangerWolf  
    OP
       2015-03-13 07:40:25 +08:00
    @dongweiming 感谢!不知道这里是不是贴代码除了gist还有什么方便的办法?
    0bit
        11
    0bit  
       2015-03-13 21:24:24 +08:00
    把beat和worker分开,分成两个命令启动试试
    RangerWolf
        12
    RangerWolf  
    OP
       2015-03-13 22:41:41 +08:00
    @0bit 确实是! 后来再继续google 发现Celery在windows还有不少坑!
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2734 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 11:22 · PVG 19:22 · LAX 04:22 · JFK 07:22
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.