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
yellowmarlboro
V2EX  ›  Python

Django 用 celery 异步 运行周期任务

  •  
  •   yellowmarlboro · 2018-11-08 11:11:45 +08:00 · 1997 次点击
    这是一个创建于 1967 天前的主题,其中的信息可能已经有所发展或是发生改变。

    目前是 django 写了一个接口, 访问之后创建任务, 现在希望能创建这些任务之后, 任务每 5 分钟运行一次. 也就是能动态添加周期任务, 目前用了 djcelery 希望 django admin 也能管理, 但是现在利用官方的这种写法并不能生效:

    def setup_periodic_tasks(sender, q, **kwargs):
        # Calls test('hello') every 10 seconds.
        sender.add_periodic_task(20.0, test.s(q), name='add every 10 min')
    

    上边的的函数调不起来 test 函数 celery shell 中没有 beat 监听到的任何消息..

    6 条回复    2018-11-09 14:42:25 +08:00
    darkTianTian
        1
    darkTianTian  
       2018-11-08 13:04:01 +08:00
    试试 django-celery-beat 这个库。
    Outliver0
        2
    Outliver0  
       2018-11-08 13:53:38 +08:00
    django-celery-beat 进行数据库迁移,可以在 admin 中管理任务
    yellowmarlboro
        3
    yellowmarlboro  
    OP
       2018-11-08 14:07:54 +08:00
    @darkTianTian @Outliver0 是的 用了这个库 可是就算用官方的写法, 也看不出来任何被调用的信息. 开不起来任务...
    xpresslink
        4
    xpresslink  
       2018-11-08 17:50:27 +08:00
    楼主提供的信息太少根本无法判断问题出在哪里了。
    比如你的 celery 服务进程跑起来了么,broker 队列里面收到任务了没有之类的都不知道。
    自己打几个断点跟踪一下,哪怕在关键点 print 一下信息也可以。
    darkTianTian
        5
    darkTianTian  
       2018-11-09 13:28:34 +08:00
    任务用 task 装饰器了吗? celery, celery beat 都启动了么,可以看 celery 的 log。
    yellowmarlboro
        6
    yellowmarlboro  
    OP
       2018-11-09 14:42:25 +08:00
    @darkTianTian @Outliver0 @xpresslink @darkTianTian 谢各位 , 装了 djcelery 同时也装 django-celery-beat 之后手贱非要升级被 djcelery 降到 3.x 的原本 4.2 的 celery 版本, 没有认真读依赖关系.
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5480 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 08:53 · PVG 16:53 · LAX 01:53 · JFK 04:53
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.