fastapi-practices / fastapi_best_architecture

基于 FastAPI 构建的前后端分离 RBAC 权限控制系统,采用独特的伪三层架构模型设计,内置 fastapi-admin 基本实现,并作为模板库免费开源;FastAPI based on the construction of the front and back end separation of RBAC privilege control system, using a unique pseudo three-tier architecture model design, built-in fastapi-admin basic implementation, and as a template library free open source.

Home Page:https://fastapi-practices.github.io/fastapi_best_architecture_docs/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

celery task exception

downdawn opened this issue · comments

commented

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

Please note the list of tasks:

image

../backend/app

image
image

I think I understand a bit now. The task registered is tasks.task_demo_async, but the task executed by the /api/v1/mixes/tests/send endpoint is backend.app.tasks.task_demo_async

image

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']...