Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Celery: launch task on start

I have a task which needs to be launched when Celery starts. This tasks is next runned every 5 minutes through a callback / eta.

I find some threads about it but nothing which seems to work on Celery 3.

Thanks for your help, Arnaud.

like image 619
arnaud.breton Avatar asked Jan 29 '13 09:01

arnaud.breton


1 Answers

Someone on the Celery's IRC channel give me the right way to do that by using the "worker_ready.connect" signal: http://docs.celeryproject.org/en/latest/userguide/signals.html#worker-ready

from celery.signals import worker_ready

@worker_ready.connect
def at_start(sender, **k):
    with sender.app.connection() as conn:
         sender.app.send_task('app.modules.task', args,connection=conn, ...)

It works like a charm now!

like image 141
arnaud.breton Avatar answered Nov 04 '22 08:11

arnaud.breton