Files
autoclip/backend/celery_app.py
Kris K 593cc62bd5 fix: desktop client, CI fixes, and backend (#61)
Squashed merge of fix/problem-fixes-from-main.

- Desktop client (Tauri v2) wiring + packaging
- CI workflow updates (Python 3.11, Rust toolchain, Tauri CLI, WebKit deps)
- Backend test fix (test_missing_api_key respects CI-injected env var)
- build_backend.py: support CI without venv + Windows-safe ASCII output

Desktop build workflows (Linux/Windows/macOS) still failing — tracked in #65.
2026-05-28 15:48:49 +08:00

52 lines
1.6 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
统一的Celery应用配置
根据环境变量选择桌面版或服务端配置
"""
import os
IS_DESKTOP = os.getenv("AUTOCLIP_DESKTOP_MODE") == "1"
if IS_DESKTOP:
# 仅桌面模式才使用文件系统 broker / sqlite backend 的轻量 Celery
from .desktop_celery import celery_app # noqa: F401
else:
# 服务端/开发常规模式Redis 或你配置的 broker/backend
from celery import Celery
broker_url = os.getenv("CELERY_BROKER_URL", "redis://localhost:6379/0")
backend_url = os.getenv("CELERY_RESULT_BACKEND", "redis://localhost:6379/1")
celery_app = Celery(__name__, broker=broker_url, backend=backend_url)
celery_app.conf.update(
task_serializer='json',
accept_content=['json'],
result_serializer='json',
timezone='Asia/Shanghai',
enable_utc=True,
task_always_eager=False, # 服务端模式异步执行
task_eager_propagates=True,
result_expires=3600,
task_ignore_result=False,
task_routes={
'backend.tasks.processing.*': {'queue': 'processing'},
'backend.tasks.video.*': {'queue': 'video'},
'backend.tasks.notification.*': {'queue': 'notification'},
'backend.tasks.maintenance.*': {'queue': 'maintenance'},
'backend.tasks.upload.*': {'queue': 'upload'},
},
)
# 自动发现任务
celery_app.autodiscover_tasks([
'backend.tasks.processing',
'backend.tasks.video',
'backend.tasks.notification',
'backend.tasks.maintenance',
'backend.tasks.upload'
])
if __name__ == '__main__':
celery_app.start()