From 124679944017be96c7015b9b82db4ad6b6814cd2 Mon Sep 17 00:00:00 2001 From: "mvarasg@unal.edu.co" Date: Mon, 5 Dec 2022 20:28:05 +0100 Subject: [PATCH] change Flask' Celery tasks docs --- docs/patterns/celery.rst | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/patterns/celery.rst b/docs/patterns/celery.rst index 228a04a8..1055470b 100644 --- a/docs/patterns/celery.rst +++ b/docs/patterns/celery.rst @@ -40,16 +40,16 @@ This is all that is necessary to integrate Celery with Flask: from celery import Celery + class ContextTask(celery.Task): + def __call__(self, *args, **kwargs): + with app.app_context(): + return self.run(*args, **kwargs) + + def make_celery(app): - celery = Celery(app.import_name) + celery = Celery(app.import_name, task_cls="minimal.minimal:ContextTask") celery.conf.update(app.config["CELERY_CONFIG"]) - class ContextTask(celery.Task): - def __call__(self, *args, **kwargs): - with app.app_context(): - return self.run(*args, **kwargs) - - celery.Task = ContextTask return celery The function creates a new Celery object, configures it with the broker