This will ensure that users/tasks.py will be loaded when Flask registers the blueprint and the tasks will be found by the Celery worker.
Update app.py:
from project import create_app, ext_celeryapp =create_app()celery = ext_celery.celery
Manual Test Run a worker in one terminal window:
(env)$ celery -A app.celery worker --loglevel=info -P gevent[config].> app: default:0x110bdea60 (.default.Loader).> transport: redis://127.0.0.1:6379/0.> results: redis://127.0.0.1:6379/0.> concurrency:16 (prefork).> task events:OFF (enable -E to monitor tasks in this worker)[queues].> celery exchange=celery(direct) key=celery[tasks]. project.users.tasks.divide
Enter the Flask shell in a new terminal:
(env)$ FLASK_APP=app.py flask shellSend some tasks to the Celery worker:>>>from project.users.tasks import divide>>> task = divide.delay(1, 2)Back in the first terminal window, you should see the logs from the worker:[2021-09-1609:44:51,516: INFO/MainProcess] Task project.users.tasks.divide[566a69b5-ce41-496f-8939-a69cb2bdbf54] received[2021-09-1609:44:56,531: INFO/ForkPoolWorker-8] Task project.users.tasks.divide[566a69b5-ce41-496f-8939-a69cb2bdbf54] succeeded in5.012977000907995s:0.5