i'm close getting celery work django+docker-compose project, have problem worker never recognizes task given it. basic idea have function insertintodatabase
called task:
myapp/tasks.py:
@task(name='tasks.db_ins') def db_ins_task(datapoints, user, description): utils.db.databaseinserter import insertintodatabase insertintodatabase(datapoints, user, description)
and in views.py
, do:
from .tasks import db_ins_task ... db_ins_task.delay(datapoints, user, description)
datapoints
list of dictionaries , user
, description
strings. problem is, when celery worker container starts, db_ins_task
never found 1 of listed tasks, when try upload website, following sort of error:
worker_1 | [2015-09-25 19:38:00,205: error/mainprocess] received unregistered task of type u'tasks.db_ins'. worker_1 | message has been ignored , discarded. worker_1 | worker_1 | did remember import module containing task? worker_1 | or maybe using relative imports? worker_1 | please see http://bit.ly/glye1c more information. ... worker_1 | traceback (most recent call last): worker_1 | file "/usr/local/lib/python2.7/site-packages/celery/worker/consumer.py", line 455, in on_task_received worker_1 | strategies[name](message, body, worker_1 | keyerror: u'tasks.db_ins'
i've been trying worker recognize task, including adding setting settings.py
:
celery_imports = ('myapp.tasks',)
i added debug logging tasks.py
make sure wasn't being missed, , can confirm every time try run task, logger reports tasks.py
being run. reference, here's worker
container in docker-compose.yml
:
worker: build: . links: - redis command: bash -c "celery -a myproj worker --app=taskman.celery --loglevel=debug"
celery.py
in separate app named taskman
. not doing right causing error tasks?
in question show starting worker with:
celery -a myproj worker --app=taskman.celery --loglevel=debug
now, problem -a
, --app
mean same thing. suggests me you've been waffling between using myproj
or taskman.celery
holder of celery app. worker uses taskman.celery
, because testing i've found if combination of -a
or --app
given single worker invocation last 1 used.
this being said, there 1 way can imagine problem happening. if myapp/tasks.py
file gets task
decorator myproj.celery.app
rather taskman.celery.app
, you'd registering tasks wrong app.
Comments
Post a Comment