celery task exception
downdawn opened this issue · comments
When I was testing the task of sending an email, an exception occurred:
@celery_app.task
def send_active_email(email: str, active_url: str) -> str:
send_verification_code_email(to=email, active_url=active_url)
print(f'发送激活邮件到 {email} 成功')
return 'Success'
KeyError: 'backend.app.tasks.send_active_email'
Request interface: /api/v1/mixes/tests/send
KeyError: 'backend.app.tasks.task_demo_async'
Received unregistered task of type 'backend.app.tasks.task_demo_async'.
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
https://docs.celeryq.dev/en/latest/internals/protocol.html
for more information.
I seem to have a solution.
You can automatically search for global tasks or add task search paths in thecelery app.
I can't use the computer to deal with it at present. Maybe tomorrow or the day after tomorrow.
Hi, @downdawn
Can you provide startup logs for celery? I think you use this command to start celery: celery -A tasks worker --loglevel=INFO
Yes, the app.autodiscover_tasks(packages=['backend.app'])
in PR doesn't work for you?
Or, as a last resort, try celery_app.send_task('task_demo_async')
Yes, the
app.autodiscover_tasks(packages=['backend.app'])
in PR doesn't work for you?
Already working,
Sorry, I didn't see packages=['backend.app']
...