Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flask Error: Unable to load celery application

Please help me to get out of this problem I am getting this when I am running

celery -A app.celery worker --loglevel=info

Error:

Unable to load celery application.
The module app.celery was not found.

My code is--

#  Celery Configuration
from celery import Celery
from app import app
print("App Name=",app.import_name)

celery=Celery(app.name,broker=app.config['CELERY_BROKER_URL'])
celery.conf.update(app.config)

@celery.task
def download_content():
    return "hello"

directory structure-- newYoutube/app/auth/routes.py and this function is present inside routes.py auth is blueprint.

like image 345
Mohd Mujtaba Avatar asked Jan 01 '23 09:01

Mohd Mujtaba


1 Answers

When invoking celery via

celery -A app.celery ...

celery will look for the name celery in the app namespace, expecting it to hold an instance of Celery. If you put that elsewhere (say, in app.auth.routes), then celery won't find it.

I have a working example you can crib from at https://github.com/davewsmith/flask-celery-starter

Or, refer to chapter 22 of the Flask Mega Tutorial, which uses rx instead of celery, but the general approach to structuring the code is similar.

like image 196
Dave W. Smith Avatar answered Jan 02 '23 22:01

Dave W. Smith