简体   繁体   English

芹菜定期任务在Django asnyc

[英]celery periodic task as asnyc on django

I'm not good at english, so if you cannot understand my sentence, give me any comment. 我的英语不好,所以如果您听不懂我的句子,请给我评论。

I use celery for periodic task on django. 我在芹菜上用芹菜做定期任务。

CELERYBEAT_SCHEDULE = {
    'send_sms_one_pm': {
        'task': 'tasks.send_one_pm',
        'schedule': crontab(minute=0, hour=13),
    },
    'send_sms_ten_am': {
        'task': 'tasks.send_ten_am',
        'schedule': crontab(minute=0, hour=10),
    },
    'night_proposal_noti': {
        'task': 'tasks.night_proposal_noti',
        'schedule': crontab(minute=0, hour=10)
    },
}

This is my celery schedule and i use redis for celery queue. 这是我的芹菜时间表,我将redis用于芹菜队列。

Problem is, when the biggest task is start, other task is on hold. 问题是,当最大的任务开始时,其他任务被搁置。 biggest task will be processed for 10hours, and, other tasks are start after 10 hours. 最大的任务将处理10个小时,其他任务将在10个小时后开始。

My task looks like 我的任务看起来像

@app.task(name='tasks.send_one_pm')
def send_one_pm():

I found, celery give me task.apply_asnyc(), but couldn't find periodic tasks can working on asnyc. 我发现,芹菜给了我task.apply_asnyc(),但是找不到可以执行asnyc的定期任务。

So, i want to know celery's periodic task can work as asnyc task. 因此,我想知道芹菜的定期任务可以像asnyc任务一样工作。 my celery worker are 8 workers. 我的芹菜工人是8名工人。

Did you assign CELERYBEAT_SCHEDULER = 'djcelery.schedulers.DatabaseScheduler' in your settings as well? 您是否CELERYBEAT_SCHEDULER = 'djcelery.schedulers.DatabaseScheduler'设置中分配了CELERYBEAT_SCHEDULER = 'djcelery.schedulers.DatabaseScheduler' If you want one task starts to run after another one, you should use apply_asnyc() with link kwargs , it looks like this: 如果您希望一个任务在另一个任务之后开始运行,则应将apply_asnyc()与链接kwargs ,如下所示:

res=[signature(your_task.name, args=(...), options=kwargs, immutable=True),..]
task.apply_async((args), link=res)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM