I have the following codes to test chord tasks with two apps (could be deployed on different worker nodes), why does it throw "unregistered task of type" issue? How can I fix it? Any suggestion would be appreciated.
celery: 4.0.2
python: 3.5
app1.py
from celery import Celery
from celery import chord
from celery.utils.log import get_task_logger
logger = get_task_logger(__name__)
app = Celery("app1", broker="redis://localhost:6379/10", backend="redis://localhost:6379/11")
if __name__ == "__main__":
app.start()
@app.task
def app1_task(s):
from app2 import app2_task
tasks = [app2_task.s("app2_task_1"), app2_task.s("app2_task_2"), app2_task.s("app2_task_3")]
workflow = chord(tasks, body=app1_task_callback.s())
workflow.apply_async()
return "app1_task is {0}".format(s)
@app.task
def app1_task_callback(res):
return "app1_task1_callback is {0}".format(res)
app2.py
import time
from celery import Celery
from celery.utils.log import get_task_logger
logger = get_task_logger(__name__)
app = Celery("app1", broker="redis://localhost:6379/12", backend="redis://localhost:6379/13")
if __name__ == "__main__":
app.start()
@app.task
def app2_task(s):
time.sleep(5)
return "app2_task2 is {0}".format(s)
Start two apps using the following command:
_celery multi start test_app1 -A app1 --pidfile=logs/app1.pid -l info -f logs/app1.log
celery multi start testapp2 -A app2 --pidfile=logs/app2.pid -l info -f logs/app2.log
[2017-01-03 23:34:08,173: INFO/MainProcess] Connected to redis://localhost:6379/10
[2017-01-03 23:34:08,180: INFO/MainProcess] mingle: searching for neighbors
[2017-01-03 23:34:09,196: INFO/MainProcess] mingle: all alone
[2017-01-03 23:34:09,204: INFO/MainProcess] test_app1@rw-MacBook-Pro.local ready.
[2017-01-03 23:34:11,235: INFO/MainProcess] Received task: app1.app1_task[6788aade-1f1b-4046-9f9a-d7aaa7dab860]
[2017-01-03 23:34:11,268: INFO/PoolWorker-3] Task app1.app1_task[6788aade-1f1b-4046-9f9a-d7aaa7dab860] succeeded in 0.032366810000894475s: 'app1_task is test1'
app2.log
[2017-01-03 23:34:08,798: INFO/MainProcess] Connected to redis://localhost:6379/12
[2017-01-03 23:34:08,806: INFO/MainProcess] mingle: searching for neighbors
[2017-01-03 23:34:09,825: INFO/MainProcess] mingle: all alone
[2017-01-03 23:34:09,837: INFO/MainProcess] test_app2@rw-MacBook-Pro.local ready.
[2017-01-03 23:34:11,266: INFO/MainProcess] Received task: app2.app2_task[ebdc3d10-1e60-4b68-a740-525aaf8430dd]
[2017-01-03 23:34:11,268: INFO/MainProcess] Received task: app2.app2_task[d9b7a304-3dfe-4be3-a554-a0c45f7824ff]
[2017-01-03 23:34:11,270: INFO/MainProcess] Received task: app2.app2_task[299136c8-0b51-419a-8507-868baad4d85c]
[2017-01-03 23:34:16,280: INFO/PoolWorker-2] Task app2.app2_task[ebdc3d10-1e60-4b68-a740-525aaf8430dd] succeeded in 5.009632268000132s: 'app1_task1 input is app2_task_1'
[2017-01-03 23:34:16,280: INFO/PoolWorker-3] Task app2.app2_task[d9b7a304-3dfe-4be3-a554-a0c45f7824ff] succeeded in 5.009859617999609s: 'app1_task1 input is app2_task_2'
[2017-01-03 23:34:16,303: INFO/PoolWorker-7] Task app2.app2_task[299136c8-0b51-419a-8507-868baad4d85c] succeeded in 5.031090483000298s: 'app1_task1 input is app2_task_3'
[2017-01-03 23:34:16,303: ERROR/MainProcess] Received unregistered task of type 'app1.app1_task_callback'.
The message has been ignored and discarded.
Did you remember to import the module containing this task?
Or maybe you're using relative imports?
The full contents of the message body was:
b'[[["app1_task1 input is app2_task_1", "app1_task1 input is app2_task_2", "app1_task1 input is app2_task_3"]], {}, {"errbacks": null, "chain": null, "callbacks": null, "chord": null}]' (182b)
Traceback (most recent call last):
File "/Users/rudongw/work/projects/isplunk/venv/lib/python3.5/site-packages/celery/worker/consumer/consumer.py", line 559, in on_taskreceived
strategy = strategies[type]
KeyError: 'app1.app1_task_callback'
I have the following codes to test chord tasks with two apps (could be deployed on different worker nodes), why does it throw "unregistered task of type" issue? How can I fix it? Any suggestion would be appreciated.
celery: 4.0.2 python: 3.5
app1.py
app2.py
Start two apps using the following command:
_celery multi start test_app1 -A app1 --pidfile=logs/app1.pid -l info -f logs/app1.log celery multi start testapp2 -A app2 --pidfile=logs/app2.pid -l info -f logs/app2.log
To test tasks:
app1.log
[2017-01-03 23:34:08,173: INFO/MainProcess] Connected to redis://localhost:6379/10 [2017-01-03 23:34:08,180: INFO/MainProcess] mingle: searching for neighbors [2017-01-03 23:34:09,196: INFO/MainProcess] mingle: all alone [2017-01-03 23:34:09,204: INFO/MainProcess] test_app1@rw-MacBook-Pro.local ready. [2017-01-03 23:34:11,235: INFO/MainProcess] Received task: app1.app1_task[6788aade-1f1b-4046-9f9a-d7aaa7dab860]
[2017-01-03 23:34:11,268: INFO/PoolWorker-3] Task app1.app1_task[6788aade-1f1b-4046-9f9a-d7aaa7dab860] succeeded in 0.032366810000894475s: 'app1_task is test1'
app2.log
[2017-01-03 23:34:08,798: INFO/MainProcess] Connected to redis://localhost:6379/12 [2017-01-03 23:34:08,806: INFO/MainProcess] mingle: searching for neighbors [2017-01-03 23:34:09,825: INFO/MainProcess] mingle: all alone [2017-01-03 23:34:09,837: INFO/MainProcess] test_app2@rw-MacBook-Pro.local ready. [2017-01-03 23:34:11,266: INFO/MainProcess] Received task: app2.app2_task[ebdc3d10-1e60-4b68-a740-525aaf8430dd]
[2017-01-03 23:34:11,268: INFO/MainProcess] Received task: app2.app2_task[d9b7a304-3dfe-4be3-a554-a0c45f7824ff]
[2017-01-03 23:34:11,270: INFO/MainProcess] Received task: app2.app2_task[299136c8-0b51-419a-8507-868baad4d85c]
[2017-01-03 23:34:16,280: INFO/PoolWorker-2] Task app2.app2_task[ebdc3d10-1e60-4b68-a740-525aaf8430dd] succeeded in 5.009632268000132s: 'app1_task1 input is app2_task_1' [2017-01-03 23:34:16,280: INFO/PoolWorker-3] Task app2.app2_task[d9b7a304-3dfe-4be3-a554-a0c45f7824ff] succeeded in 5.009859617999609s: 'app1_task1 input is app2_task_2' [2017-01-03 23:34:16,303: INFO/PoolWorker-7] Task app2.app2_task[299136c8-0b51-419a-8507-868baad4d85c] succeeded in 5.031090483000298s: 'app1_task1 input is app2_task_3' [2017-01-03 23:34:16,303: ERROR/MainProcess] Received unregistered task of type 'app1.app1_task_callback'. The message has been ignored and discarded.
Did you remember to import the module containing this task? Or maybe you're using relative imports?
Please see http://docs.celeryq.org/en/latest/internals/protocol.html for more information.
The full contents of the message body was: b'[[["app1_task1 input is app2_task_1", "app1_task1 input is app2_task_2", "app1_task1 input is app2_task_3"]], {}, {"errbacks": null, "chain": null, "callbacks": null, "chord": null}]' (182b) Traceback (most recent call last): File "/Users/rudongw/work/projects/isplunk/venv/lib/python3.5/site-packages/celery/worker/consumer/consumer.py", line 559, in on_taskreceived strategy = strategies[type] KeyError: 'app1.app1_task_callback'