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.

up vote 7 down vote accepted

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

@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!

You need to define in the settings:

import djcelery
djcelery.setup_loader()
CELERY_IMPORTS = ("apps.app_name.module.tasks",)

Also if you dont have instaled celery broker you should install one I am using RabbitMQ, very good tutorial for how to use it you have in the celery documentation:

http://docs.celeryproject.org/en/latest/getting-started/brokers/rabbitmq.html

And then start from command line celery demon:

django-admin.py celeryd -v 2 -B -s celery -E -l INFO

  • Hi, thanks for the answer but I don't think it's what I'm looking for. CELERY_IMPORTS settings lets you define customs modules to import (if you didn't put your tasks in tasks.py). What I'm looking for is a way to automatically start a specific task when the deamon is starting. Next the callback / ETA system is doing the rest. Thanks for your help. – arnaud.breton Jan 29 '13 at 17:41

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.