Mixing django-celery and standalone celery

穿精又带淫゛_ 提交于 2019-12-04 17:07:51

That is easily possible.

If you have a pure-python Celery worker, you can send tasks by name as long as you use the same broker URL:

from celery import Celery
celery = Celery(broker='amqp://guest@localhost//')

then in some view:

 celery.send_task('send_message', kwargs={
     'fromUser': ...,
 })

You can also schedule your tasks in configuration with CELERYBEAT_SCHEDULE:

CELERYBEAT_SCHEDULE = {
        'scheduled_task':{
            'task':'name in your task decorator',
            'schedule': timedelta(...),
            'args': (..., ),
        }
    }

But your worker has to be run with celery beat (-B):

celery -A app.tasks worker -B -l info
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!