Django celery task starts immediately when the celery server starts

I need to find how to specify some kind of initial celery task that will run all the other tasks in a specific way. This initial task should start immediately upon starting the celery server and should never start again.

+6
source share
2 answers

How about using celeryd_after_setup or celeryd_init signal?

Sample Follwing code from the documentation:

 from celery.signals import celeryd_init @celeryd_init.connect(sender=' worker12@example.com ') def configure_worker12(conf=None, **kwargs): ... 
+9
source

I found a way to do this. It has one negative side - it is impossible to indicate the current year, and the task will be launched again in a year. But usually the server restarts more often, then this period.

 from celery.task import PeriodicTask class InitialTasksStarter(PeriodicTask): starttime = datetime.now() + timedelta(minutes=1) run_every = crontab(month_of_year=starttime.month, day_of_month=starttime.day, hour=starttime.hour, minute=starttime.minute) def run(self, **kwargs): .... return True 
0
source

Source: https://habr.com/ru/post/959076/


All Articles