23👍
✅
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!
0👍
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
- Ignore a specific test using Django
- Pycharm error: Improperly configured
- Django datefield and timefield to python datetime
- Passing a variable in redirect in Django
Source:stackexchange.com