【发布时间】:2019-03-04 09:23:09
【问题描述】:
我有一个带有多个 celery beat 任务的 Django 项目,当我有多个带有单独队列的 celery beat 任务时遇到问题,所以我有可能一次运行所有这些,运行的最佳实践是什么这些?
from __future__ import absolute_import, unicode_literals
import os
from celery import Celery
from celery import Celery
from celery.schedules import crontab
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'projectDemon.settings')
app = Celery('projectDemon')
app.config_from_object('django.conf:settings', namespace='CELERY')
app.autodiscover_tasks()
@app.on_after_configure.connect
def setup_periodic_tasks(sender, **kwargs):
sender.add_periodic_task(
crontab(minute=30, hour='7'),
task1.s('Checking task1 !'),
queue= 'task1',
options={
'queue': 'task1',
'routing_key': 'task1'}
)
sender.add_periodic_task(
crontab(minute=00, hour='6'),
task2.s('Checking task2 !'),
queue= 'task2',
options={
'queue': 'task2',
'routing_key': 'task2'}
)
sender.add_periodic_task(
crontab(
minute='*/1', # run every minute
),
task3.s('Checking task3 !'),
queue= 'task3',
options={
'queue': 'task3',
'routing_key': 'task3'}
)
@app.task
def task1(arg):
print(arg)
@app.task
def task2(arg):
print(arg)
@app.task
def task3(arg):
print(arg)
【问题讨论】:
-
您能否详细说明您的问题是什么?我可以根据我这样做的方式来回答(这是不同的),但我不确定你面临什么问题
标签: python django celery celerybeat