PaperParser/app/celery.py

18 lines
591 B
Python
Raw Permalink Normal View History

2024-01-31 19:37:01 +10:00
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