ayushkhare12

Make Celery

Aug 7th, 2019
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.46 KB | None | 0 0
  1. from celery import Celery
  2.  
  3. def make_celery(app):
  4.     celery = Celery(
  5.         app.import_name,
  6.         backend=app.config['CELERY_RESULT_BACKEND'],
  7.         broker=app.config['CELERY_BROKER_URL']
  8.     )
  9.     celery.conf.update(app.config)
  10.  
  11.     class ContextTask(celery.Task):
  12.         def __call__(self, *args, **kwargs):
  13.             with app.app_context():
  14.                 return self.run(*args, **kwargs)
  15.  
  16.     celery.Task = ContextTask
  17.     return celery
Add Comment
Please, Sign In to add comment