feat: centralize Celery task imports in extensions and update worker initialization

This commit is contained in:
Your Name
2026-03-22 21:51:38 +02:00
parent 46bc0441b4
commit cb5111737b
3 changed files with 28 additions and 18 deletions

2
.gitignore vendored
View File

@@ -56,3 +56,5 @@ coverage/
backend/celerybeat-schedule backend/celerybeat-schedule
backend/data/dociva.db backend/data/dociva.db
docs/

View File

@@ -13,6 +13,28 @@ talisman = Talisman()
celery = Celery() celery = Celery()
def import_celery_tasks() -> None:
"""Import all Celery task modules so task registration is centralized."""
import app.tasks.barcode_tasks # noqa: F401
import app.tasks.compress_image_tasks # noqa: F401
import app.tasks.compress_tasks # noqa: F401
import app.tasks.convert_tasks # noqa: F401
import app.tasks.flowchart_tasks # noqa: F401
import app.tasks.html_to_pdf_tasks # noqa: F401
import app.tasks.image_tasks # noqa: F401
import app.tasks.maintenance_tasks # noqa: F401
import app.tasks.ocr_tasks # noqa: F401
import app.tasks.pdf_ai_tasks # noqa: F401
import app.tasks.pdf_convert_tasks # noqa: F401
import app.tasks.pdf_editor_tasks # noqa: F401
import app.tasks.pdf_extra_tasks # noqa: F401
import app.tasks.pdf_to_excel_tasks # noqa: F401
import app.tasks.pdf_tools_tasks # noqa: F401
import app.tasks.qrcode_tasks # noqa: F401
import app.tasks.removebg_tasks # noqa: F401
import app.tasks.video_tasks # noqa: F401
def init_celery(app): def init_celery(app):
"""Initialize Celery with Flask app context.""" """Initialize Celery with Flask app context."""
celery.conf.broker_url = app.config["CELERY_BROKER_URL"] celery.conf.broker_url = app.config["CELERY_BROKER_URL"]
@@ -63,4 +85,5 @@ def init_celery(app):
return self.run(*args, **kwargs) return self.run(*args, **kwargs)
celery.Task = ContextTask celery.Task = ContextTask
import_celery_tasks()
return celery return celery

View File

@@ -1,22 +1,7 @@
"""Celery worker entry point.""" """Celery worker entry point."""
from app import create_app from app import create_app
from app.extensions import celery from app.extensions import celery, import_celery_tasks
app = create_app() app = create_app()
# Import all tasks so Celery discovers them import_celery_tasks()
import app.tasks.convert_tasks # noqa: F401
import app.tasks.compress_tasks # noqa: F401
import app.tasks.image_tasks # noqa: F401
import app.tasks.video_tasks # noqa: F401
import app.tasks.pdf_tools_tasks # noqa: F401
import app.tasks.flowchart_tasks # noqa: F401
import app.tasks.maintenance_tasks # noqa: F401
import app.tasks.ocr_tasks # noqa: F401
import app.tasks.removebg_tasks # noqa: F401
import app.tasks.pdf_editor_tasks # noqa: F401
import app.tasks.compress_image_tasks # noqa: F401
import app.tasks.pdf_to_excel_tasks # noqa: F401
import app.tasks.qrcode_tasks # noqa: F401
import app.tasks.html_to_pdf_tasks # noqa: F401
import app.tasks.pdf_ai_tasks # noqa: F401