简体   繁体   中英

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.

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.

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.

So, i want to know celery's periodic task can work as asnyc task. my celery worker are 8 workers.

Did you assign CELERYBEAT_SCHEDULER = 'djcelery.schedulers.DatabaseScheduler' in your settings as well? If you want one task starts to run after another one, you should use apply_asnyc() with link kwargs , it looks like this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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