* Fix pylint warnings across all 24 Python files in web_server - Add module, class, and function docstrings (C0114, C0115, C0116) - Fix import ordering: stdlib before third-party before local (C0411) - Replace wildcard imports with explicit named imports (W0401) - Remove trailing whitespace and add missing final newlines (C0303, C0304) - Replace dict() with dict literals (R1735) - Remove unused imports and variables (W0611, W0612) - Narrow broad Exception catches to specific exceptions (W0718) - Replace f-string logging with lazy % formatting (W1203) - Fix variable naming: UPPER_CASE for constants, snake_case for locals (C0103) - Add pylint disable comments for necessary global statements (W0603) - Fix no-else-return, simplifiable-if-expression, singleton-comparison - Fix bad indentation in stripe.py (W0311) - Add encoding="utf-8" to open() calls (W1514) - Add check=True to subprocess.run() calls (W1510) - Register Celery task modules via conf.include * Update `package-lock.json` add peer dependencies
29 lines
947 B
Python
29 lines
947 B
Python
"""Celery configuration and Flask app context setup for async tasks."""
|
|
|
|
from celery import Celery, Task
|
|
|
|
|
|
def celery_init_app(app) -> Celery:
|
|
"""Initialize Celery with Flask application context."""
|
|
class FlaskTask(Task):
|
|
"""Celery task that runs within Flask app context."""
|
|
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.conf.beat_schedule = {
|
|
'user-favourability-task': {
|
|
'task': 'celery_tasks.preferences.user_preferences',
|
|
'schedule': 30.0,
|
|
},
|
|
}
|
|
celery_app.conf.include = [
|
|
'celery_tasks.preferences',
|
|
'celery_tasks.streaming',
|
|
]
|
|
celery_app.set_default()
|
|
app.extensions["celery"] = celery_app
|
|
return celery_app
|