0

This is the beat tasks setting:

celery_app.conf.update(
CELERYBEAT_SCHEDULE = {
'taskA': {
    'task': 'crawlerapp.tasks.manual_crawler_update',
    'schedule': timedelta(seconds=3600),
},
'taskB': {
    'task': 'crawlerapp.tasks.auto_crawler_update_day',
    'schedule': timedelta(seconds=3600),
},
'taskC': {
    'task': 'crawlerapp.tasks.auto_crawler_update_hour',
    'schedule': timedelta(seconds=3600),
},
})

Normally taskA,taskB,taskC execute at the same time after my command celery -A myproj beat as the beat tasks. But now I want that taskA execute first,and then some time later taskB excute second,taskC excute at last.And after 3600 seconds they excute again.And after 3600 seconds they excute again.And after 3600 seconds they excute again. Is it possible?

Chillar Anand
  • 27,936
  • 9
  • 119
  • 136
no13bus
  • 347
  • 1
  • 4
  • 15

1 Answers1

1

Yeah, it's possible. Create a chain for all three tasks and then use this chained task for scheduling.

In your tasks.py file:

from celery import chain
chained_task = chain(taskA, taskB, taskC)

Then schedule the chained_task:

celery_app.conf.update(
CELERYBEAT_SCHEDULE = {
'chained_task': {
    'task': 'crawlerapp.tasks.manual_crawler_update',
    'schedule': timedelta(seconds=3600),
},  
})

By this, your task will execute in order once in 3600 seconds.

Chillar Anand
  • 27,936
  • 9
  • 119
  • 136
  • but I have 3 tasks functions: manual_crawler_update, auto_crawler_update_day, auto_crawler_update_hour.you mean that these 3 tasks are tasksA taskB taskC?? – no13bus Sep 22 '14 at 13:33
  • Yes, those 3 tasks can be anything as long as they have task decorator. – Chillar Anand Sep 22 '14 at 13:53
  • hi,can I ask you another question?Is it possible that I just stop the taskA,and at the same time,taskB and taskC is still work.Because when the taskA have bugs,I must stop the celery beat tasks together and then after I modify the bugs I start the beat tasks together. – no13bus Oct 07 '14 at 08:06
  • I dont think its possible as the result of first task might affect the next task. Do checkout http://stackoverflow.com/questions/17461374/celery-stop-execution-of-a-chain – Chillar Anand Oct 07 '14 at 09:40
  • Just ignore the chains.I just have 3 tasks.They are not in a chain. – no13bus Oct 07 '14 at 09:52
  • In that case, you can do it. – Chillar Anand Oct 07 '14 at 09:57
  • ok.I checkout the url first.thanks very much. Can we communicate about python web framework or some other python awesome app? My email is no13bus@gmail.com – no13bus Oct 07 '14 at 10:11