Received unregistered task of type KeyError('modules.callback.tasks.check_transaction')

Viewed 172

I'm trying to execute chains of task with celery, this is my tasks:

from config import celery_app
from modules.transaction.models import Transaction
import logging


logger = logging.getLogger('callback_log')


@celery_app.task
def get_transaction(transaction_id):
    transaction = Transaction.objects.last().__dict__
    if transaction.get("_state"):
        transaction.pop("_state")
    return transaction_id, transaction


@celery_app.task
def check_transaction(transaction_id, transaction_dict):
    return transaction_dict["id"] == transaction_id: 

and this is my celery app

import os

from celery import Celery


os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")

app = Celery("toolbox",include=["modules.callback.tasks"])
app.config_from_object("django.conf:settings", namespace="CELERY")
app.autodiscover_tasks()

and where I used tasks:

from celery import chain

from modules.callback.tasks import get_transaction, check_transaction


@action(methods=["GET"], detail=False)
def test_chain(self, request):
    chain(get_transaction.s(234) | check_transaction.s()).apply_async()
    return Response({})

after starting celery with this command: celery -A config worker -l info

celery prints:

 -------------- celery@SUSE v4.4.6 (cliffs)
--- ***** ----- 
-- ******* ---- Linux-5.7.7-1-default-x86_64-with-glibc2.2.5 2020-07-18 16:10:21
- *** --- * --- 
- ** ---------- [config]
- ** ---------- .> app:         toolbox:0x7f731f2dbfa0
- ** ---------- .> transport:   amqp://FAKE_USER:**@XXX.XXX.XXX.XX:XXXX//
- ** ---------- .> results:     amqp://
- *** --- * --- .> concurrency: 4 (prefork)
-- ******* ---- .> task events: OFF (enable -E to monitor tasks in this worker)
--- ***** ----- 
 -------------- [queues]
                .> celery           exchange=celery(direct) key=celery
                

[tasks]
  . modules.callback.tasks.check_transaction
  . modules.callback.tasks.get_transaction

after executing chain, the first task will execute successfully but for the second task it throws this exception:

Received unregistered task of type KeyError('modules.callback.tasks.check_transaction').
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 were:
'[[12, {}, ""], {}, {"callbacks": null, "errbacks": null, "chain": [], "chord": null}]' (85b)

Django==2.2

celery==4.4.6

i tried to run celery in debug level but it shows nothing useful, why celery says unregistered task?

0 Answers
Related