Reputation: 179
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.
Upvotes: 7
Views: 11938
Reputation: 113
Return both celery and app from your create_app function if you are using one e.g
def create_app():
app = Flask(__name__)
# app config ...
celery=Celery(app.name,broker=app.config['CELERY_BROKER_URL'])
celery.conf.update(app.config)
return app, celery
Upvotes: 0
Reputation: 24956
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.
Upvotes: 10