Reputation:
I have a tasks module in which, we basically do the following:
def make_celery(app):
celery = Celery(app.import_name, broker=app.config['CELERY_BROKER_URL'])
celery.conf.update(app.config)
TaskBase = celery.Task
class ContextTask(TaskBase):
abstract = True
def __call__(self, *args, **kwargs):
with app.app_context():
return TaskBase.__call__(self, *args, **kwargs)
celery.Task = ContextTask
return celery
@celery.task(name="tasks.add")
def add(x, y):
return x + y
The celery app is then created as so:
celery = tasks.make_celery(app)
Where app is a flask app
For configs I am using:
CELERY_BROKER_URL = str(os.environ.get("CELERY_BROKER_URL", 'redis://localhost:6379/0'))
CELERY_RESULT_BACKEND = str(os.environ.get("CELERY_RESULT_BACKEND", 'redis://localhost:6379/0'))
I am following the tutorial in http://flask.pocoo.org/docs/patterns/celery/
However, when I run the worker, I see that it is starting, and it lists my add task then it hangs (never displays the ready message).
Upvotes: 1
Views: 947
Reputation: 542
I am experiencing identical symptoms and was able to narrow the problem down to Flask-SocketIO. While this probably isn't directly what's causing OP's problem, it could be related or relevant for future visitors with identical symptoms.
I documented my problem here: https://github.com/miguelgrinberg/Flask-SocketIO/issues/61
Also, not enough reputation to post as comment.
Upvotes: 1