推荐学习书目
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 · Nov 8, 2018 · 2585 views
    This topic created in 2835 days ago, the information mentioned may be changed or developed.

    目前是 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 replies    2018-11-09 14:42:25 +08:00
    darkTianTian
        1
    darkTianTian  
       Nov 8, 2018
    试试 django-celery-beat 这个库。
    Outliver0
        2
    Outliver0  
       Nov 8, 2018
    django-celery-beat 进行数据库迁移,可以在 admin 中管理任务
    yellowmarlboro
        3
    yellowmarlboro  
    OP
       Nov 8, 2018
    @darkTianTian @Outliver0 是的 用了这个库 可是就算用官方的写法, 也看不出来任何被调用的信息. 开不起来任务...
    xpresslink
        4
    xpresslink  
       Nov 8, 2018
    楼主提供的信息太少根本无法判断问题出在哪里了。
    比如你的 celery 服务进程跑起来了么,broker 队列里面收到任务了没有之类的都不知道。
    自己打几个断点跟踪一下,哪怕在关键点 print 一下信息也可以。
    darkTianTian
        5
    darkTianTian  
       Nov 9, 2018
    任务用 task 装饰器了吗? celery, celery beat 都启动了么,可以看 celery 的 log。
    yellowmarlboro
        6
    yellowmarlboro  
    OP
       Nov 9, 2018
    @darkTianTian @Outliver0 @xpresslink @darkTianTian 谢各位 , 装了 djcelery 同时也装 django-celery-beat 之后手贱非要升级被 djcelery 降到 3.x 的原本 4.2 的 celery 版本, 没有认真读依赖关系.
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3075 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 14:40 · PVG 22:40 · LAX 07:40 · JFK 10:40
    ♥ Do have faith in what you're doing.