18 lines
591 B
Python
18 lines
591 B
Python
from flask import Flask
|
|
from celery import Celery
|
|
from celery.contrib.abortable import AbortableTask
|
|
from app.blueprints.api.tasks.handlers import *
|
|
|
|
def celery_init_app(app: Flask) -> Celery:
|
|
class FlaskTask(AbortableTask):
|
|
def __call__(self, *args: object, **kwargs: object) -> object:
|
|
with app.app_context():
|
|
return self.run(*args, **kwargs)
|
|
|
|
celery_app = Celery(app.name, task_cls=FlaskTask)
|
|
|
|
celery_app.config_from_object(app.config["CELERY"])
|
|
celery_app.set_default()
|
|
app.extensions["celery"] = celery_app
|
|
return celery_app
|
|
|