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

celery 到底能不能动态添加周期任务

  •  
  •   hanssx · 2019-08-23 22:23:37 +08:00 · 3113 次点击
    这是一个创建于 1698 天前的主题,其中的信息可能已经有所发展或是发生改变。
    动态即通过前端 UI 等手段自定义周期时间,而不是通过初始化时写配置文件,经过 gg 和实践摸索,发现并不能实现动态添加周期任务。
    https://stackoverflow.com/questions/10194975/how-to-dynamically-add-remove-periodic-tasks-to-celery-celerybeat/43752416
    倒数第 3 个回答,提到了文档中的使用 https://docs.celeryproject.org/en/latest/userguide/periodic-tasks.html#entries
    然后我使用文档中的例子 add_periodic_task,并没有成功,文档中说的不是动态添加?
    13 条回复    2019-08-27 14:17:43 +08:00
    GoLand
        1
    GoLand  
       2019-08-23 22:26:20 +08:00   ❤️ 1
    添加了 periodic task 得重启 beat 和 celery 的,动态添加不了。
    gulu
        2
    gulu  
       2019-08-24 02:53:43 +08:00 via Android   ❤️ 1
    可以添加,但是默认没有,得自己实现。
    beat 也是周期性从文件读任务参数。
    youngce
        3
    youngce  
       2019-08-24 13:55:01 +08:00   ❤️ 1
    django celery beat 是可以实现读取数据库中动态生成的任务周期设置,来实现你说的这个需求的
    youngce
        4
    youngce  
       2019-08-24 13:55:57 +08:00
    当然你要是没有用 django 的话,其他的框架有没有提供类似的第三方包我就不清楚了
    hanssx
        5
    hanssx  
    OP
       2019-08-24 19:49:46 +08:00
    @GoLand
    @gulu
    @youngce 谢谢三位,我明白了。
    linvaux
        6
    linvaux  
       2019-08-24 22:55:24 +08:00
    最近也在学习 celery,感觉有点复杂
    Eds1995
        7
    Eds1995  
       2019-08-25 08:21:32 +08:00 via Android
    GitHub 上有一个用 redis 来实现动态添加任务的库,rebeat
    hanssx
        8
    hanssx  
    OP
       2019-08-26 11:20:14 +08:00
    @Eds1995 兄弟我没搜到你这个库啊
    hanssx
        9
    hanssx  
    OP
       2019-08-26 11:52:13 +08:00
    Eds1995
        10
    Eds1995  
       2019-08-26 14:20:23 +08:00   ❤️ 1
    hanssx
        11
    hanssx  
    OP
       2019-08-26 18:14:15 +08:00
    @Eds1995 感谢,不过不怎么会用,文档有点少。
    hanssx
        12
    hanssx  
    OP
       2019-08-26 22:05:23 +08:00
    推荐个国人写的,但是我用着有些问题,examples/base/tasks.py 文件是没有问题的,https://github.com/AngelLiang/celery-sqlalchemy-scheduler
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3134 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 14:44 · PVG 22:44 · LAX 07:44 · JFK 10:44
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.