问题
I'm running celery 3.1.11 and flower 0.6.0 .
I have a celery application configured as such;
# myapp.tasks.celery.py
from __future__ import absolute_import
from celery import Celery
class Config(object):
BROKER_URL = 'amqp://'
CELERY_RESULT_BACKEND = 'amqp'
CELERY_TASK_RESULT_EXPIRES = None
CELERY_RESULT_SERIALIZER = 'json'
CELERY_INCLUDE = [
'myapp.tasks.source',
'myapp.tasks.page',
'myapp.tasks.diffusion',
'myapp.tasks.place',
]
)
celery = Celery('myapp')
celery.config_from_object(Config)
if __name__ == '__main__':
celery.start()
I execute the celery worker using the following command:
$ celery -A myapp.tasks worker --loglevel=INFO -E -Q celery
I can see the complete list of available tasks in the worker output.
[tasks]
...
. myapp.tasks.diffusion.post_activity
...
I then execute the flower server with the following command:
$ celery -A myapp.tasks flower
Now, whenever I try to post a new task via the Flower REST API, I get a 404 error with an error message "Unknown task TASK_NAME".
[W 140423 12:16:17 web:1302] 404 POST /api/task/async-apply/myapp.tasks.diffusion.post_activity (82.225.61.194): Unknown task 'myapp.tasks.diffusion.post_activity'
[W 140423 12:16:17 web:1728] 404 POST /api/task/async-apply/myapp.tasks.diffusion.post_activity (82.225.61.194) 4.68ms
I've put a pdb breakpoint in the flower API handler, and it appears that the only tasks available when the requests is handled are the following:
ipdb> pp celery.tasks
{'celery.backend_cleanup': <@task: celery.backend_cleanup of yoda.tasks.celery:0x7fb9191eb490>,
'celery.chain': <@task: celery.chain of yoda.tasks.celery:0x7fb9191eb490>,
'celery.chord': <@task: celery.chord of yoda.tasks.celery:0x7fb9191eb490>,
'celery.chord_unlock': <@task: celery.chord_unlock of yoda.tasks.celery:0x7fb9191eb490>,
'celery.chunks': <@task: celery.chunks of yoda.tasks.celery:0x7fb9191eb490>,
'celery.group': <@task: celery.group of yoda.tasks.celery:0x7fb9191eb490>,
'celery.map': <@task: celery.map of yoda.tasks.celery:0x7fb9191eb490>,
'celery.starmap': <@task: celery.starmap of yoda.tasks.celery:0x7fb9191eb490>}
No tasks seem to be available. However, when I use the task async_apply()
method in a shell, the task is executed by the worker.
Any idea what I'm doing wrong? Thank you!
Edit: when I'm using celery 3.0.19 and flower 0.5.0, it works seemelesly.
回答1:
This error was due to a bug in Flower and now has been resolved:
Issue: https://github.com/mher/flower/issues/200
Resolving commit: https://github.com/mher/flower/commit/bfba1eec90124c92586c480aebaf98ae63c31276
回答2:
I was experiencing similar problems with flower
. My configuration was using redis.
Situation has improved at the moment I have started flower with explicit value for option "broker" (do not ask me why).
In your situation I would try
$ flower -r "amqp://"
Anyway, I would also make sure, that you start celery
and redis
from an environment, which has proper access to all your libraries.
来源:https://stackoverflow.com/questions/23241431/unknown-task-error-in-celery-flower-when-posting-a-new-task