0
votes

I am using django-celery to implementing periodic tasks flowing the doc. And I started the celery worker and beat successfully:

[tasks]

  . scheduler.tasks.test

Scheduler is the name of my app. I configure the tasks in scheduler.tasks.py and save the periodic tasks in my view.py. But after I send a HTTP requset to create a periodic task, celery beat reports an error like this:

Traceback (most recent call last):
File "/myhome/lib/python2.7/site-packages/celery/worker/consumer.py", line 455, in on_task_received strategies[name](message, body,
KeyError: u'<@task: scheduler.tasks.test of myproj:0x7f8847449910>'

I googled and found some answers about relative import issues, but the task name in the error message is the same with that of the registered task.

What else may be the problem?

EDIT:

Another evidence of scheduler.tasks.test having been registered is that if I call test.delay() rather than make it a periodic task, it can be processed successfully.

1
did you import your celery confs scheduler.tasks.py in your project's _init_.py where settings.py reside? - HassenPy
@HassenPy I am using auto discovery, so what you said is not necessary. And the log shows that the tasks has been found successfully. - Shady Xu

1 Answers

0
votes

Problem solved.

The registered task is scheduler.tasks.test, but the key to find the task from the dict is KeyError: u'<@task: scheduler.tasks.test of myproj:0x7f8847449910>'. That is to say, the key is a string, but it is given an unicode of an object.

So, remember to use the same string as key to find a task.