34 lines
783 B
Python
34 lines
783 B
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""
|
|
Celery Worker 入口點
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
# 添加專案根目錄到 Python 路徑
|
|
project_root = Path(__file__).parent
|
|
sys.path.insert(0, str(project_root))
|
|
|
|
# 導入應用和創建Celery實例
|
|
from app import create_app
|
|
|
|
# 創建應用實例
|
|
flask_app = create_app()
|
|
|
|
# 導出Celery實例供worker使用
|
|
celery = flask_app.celery
|
|
|
|
# 重要:導入任務模組以確保任務被註冊
|
|
from app.tasks import translation
|
|
|
|
# 確保可以通過celery -A celery_app訪問
|
|
__all__ = ['celery']
|
|
|
|
if __name__ == "__main__":
|
|
print("Celery app created successfully")
|
|
print(f"Flask app: {flask_app}")
|
|
print(f"Celery instance: {celery}")
|
|
print(f"Available tasks: {list(celery.tasks.keys())}") |