I am upgrading celery from 3 to 4, and I can't get class-based tasks to be registered. I can convert some of them to callables, and they can get registered, but our codebase has far more complicated tasks that simply have to keep their class structure, barring a significant amount of refactoring. Our rabbitmq server can pick up the tasks, the worker acknowledges the task, but I get the error:
[2020-03-05 22:50:18,528: ERROR/MainProcess] Received unregistered task of type 'QueuedSurvey'.
Here is the example task that fails. I am following the same format I've seen throughout the celery docs and internet:
class QueuedSurvey(celery.Task):
def run(self, profile_ids, survey_id, notification_email):
@transaction.atomic
def run_inner():
print("123")
QueuedSurvey = app.register_task(QueuedSurvey())
Here is my app:
from siphon import settings_celery
from celery import Celery
app = Celery(accept_content=['pickle'])
app.conf.task_protocol = 1
app.config_from_object(settings_celery, namespace='CELERY')
And my settings:
CELERY_TASK_IGNORE_RESULT = True
CELERY_IMPORTS = ['cal.celery.tasks', 'cal.tasks_lambda']
CELERY_TASK_ROUTES = ('cal.celery.routers.Router', )
for q in CELERY_TASK_QUEUES:
existing = CELERY_TASK_QUEUES[q]
binding = {'binding_key': q}
CELERY_TASK_QUEUES[q] = dict(list(existing.items()) + list(binding.items()))
CELERY_TASK_DEFAULT_QUEUE = 'cal.default'
CELERY_TASK_DEFAULT_EXCHANGE = 'default'
CELERY_TASK_DEFAULT_EXCHANGE_TYPE = 'direct'
CELERY_SEND_TASK_ERROR_EMAILS = True
CELERYD_LOG_LEVEL = "INFO"
CELERY_ACCEPT_CONTENT = ['pickle']
CELERY_TASK_SERIALIZER = 'pickle'
CELERY_RESULT_SERIALIZER = 'pickle'
CELERY_WORKER_PREFETCH_MULTIPLIER = 4
Again, I can convert the example task above to a callable with the @app.task decorator and all that, and it works. But staying in this format does not. Also worth noting that in Celery 3, that task also works, and it doesn't even need an app object.