Reputation: 1136
I am working on a FLASK app with Celery. In it, I run the app using the line app.run()
. If I change it to the following
if __name__ == '__main__':
application = current_app._get_current_object()
worker = worker.worker(app=application)
beat = beat.beat(app=application)
options = {
'broker': app.config['CELERY_BROKER_URL'],
'loglevel': 'INFO',
'traceback': True,
}
worker.run(**options)
beat.run(**options)
app.run()
This runs the app and the worker, but the Celery beat does not run until I shut down the worker. Is there any way that I can run both concurrently? Maybe add the -B
flag to the options settings somehow? I'd appreciate any help on the matter.
Upvotes: 2
Views: 977
Reputation: 126
If you add 'beat' = True to your options, when you call worker.run(**options) it'll give the beat task to a worker:
if __name__ == '__main__':
application = current_app._get_current_object()
worker = worker.worker(app=application)
options = {
'broker': app.config['CELERY_BROKER_URL'],
'loglevel': 'INFO',
'traceback': True,
'beat': True,
}
worker.run(**options)
app.run()
It should stop the beat when the worker stops.
Upvotes: 3