Celery: launch task at startup
2 answers
Someone from the IRC Celery channel give me the correct way to do this using the "worker_ready.connect" signal: http://docs.celeryproject.org/en/latest/userguide/signals.html#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, ...)
Now it works like a charm!
+6
source to share
You need to define in the settings:
import djcelery
djcelery.setup_loader()
CELERY_IMPORTS = ("apps.app_name.module.tasks",)
Also, if you don't have a celery broker installed, you must install one. I am using RabbitMQ, there is a very good tutorial on how to use it in the celery docs:
http://docs.celeryproject.org/en/latest/getting-started/brokers/rabbitmq.html
And then start with the command line celery daemon:
django-admin.py celeryd -v 2 -B -s celery -El INFO
0
source to share