Celery Unregistered Task
Celery simply needs a list of [effectively] paths to files that house celery tasks
So if you had a file app/blueprints/main/tasks.py , celery doesn't know about this unless you add it to the "include" list
celery = Celery(
__name__,
broker=Config.CELERY_BROKER_URL,
include=[
"app.blueprints.main.tasks",
"app.blueprints.matchmaking.tasks",
]
)
See https://github.com/slgotting/celery-flask-demonstration for the repo. Not perfect yet,
but adding to it.
Celery with app context
At this point in time I do not think it is possible to link the context between the flask website server and the celery worker.
Instead, what can be done for certain things that simply depend on static context variables, like config variables is to
create an app context for the celery worker:
#!/usr/bin/env python
import os
from app import celery, create_app
app = create_app(os.getenv('FLASK_CONFIG') or 'default')
app.app_context().push()
Then run worker with: celery -A celery_worker.celery worker --loglevel=info
These depend on celery being initialized in the app/__init__.py file:
from celery import Celery
from config import config, Config
celery = Celery(__name__, broker=Config.CELERY_BROKER_URL)
def create_app(config_name):
# ...
celery.conf.update(app.config)
# ...
return app