Answer the question
In order to leave comments, you need to log in
Flask Celery Singleton how?
I want to make the task a singleton.
utils/celery.py
def init_celery(app, celery):
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
class CelerySingleton(celery.Task, Singleton):
pass
@celery.task(base=CelerySingleton)
def calc():
# при обращении к sqlalchemy получаю
# application not registered on db instance and no application bound to current context
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question