This commit is contained in:
2025-09-24 04:51:12 +08:00
parent a54c157f9a
commit 6d37e7c23c
12 changed files with 548 additions and 101 deletions

48
app.py
View File

@@ -8,9 +8,12 @@ from services import DefaultTemplateService
from telemetry import init_opentelemetry
from util import api
# 使用新的服务架构
template_service = DefaultTemplateService()
template_service.load_local_templates()
# 使用新的服务容器架构
from services.service_container import get_template_service, register_default_services
# 确保服务已注册
register_default_services()
template_service = get_template_service()
import logging
@@ -28,14 +31,37 @@ def do_nothing():
@app.post('/<task_id>')
def do_task(task_id):
task_info = api.get_task_info(task_id)
local_template_info = template_service.get_template(task_info.get("templateId"))
template_info = api.get_template_info(task_info.get("templateId"))
if local_template_info:
if local_template_info.get("updateTime") != template_info.get("updateTime"):
template_service.download_template(task_info.get("templateId"))
biz.task.start_task(task_info)
return "OK"
try:
task_info = api.get_task_info(task_id)
if not task_info:
LOGGER.error("Failed to get task info for task: %s", task_id)
return "Failed to get task info", 400
template_id = task_info.get("templateId")
if not template_id:
LOGGER.error("Task %s missing templateId", task_id)
return "Missing templateId", 400
local_template_info = template_service.get_template(template_id)
template_info = api.get_template_info(template_id)
if not template_info:
LOGGER.error("Failed to get template info for template: %s", template_id)
return "Failed to get template info", 400
if local_template_info:
if local_template_info.get("updateTime") != template_info.get("updateTime"):
LOGGER.info("Template %s needs update, downloading...", template_id)
if not template_service.download_template(template_id):
LOGGER.error("Failed to download template: %s", template_id)
return "Failed to download template", 500
biz.task.start_task(task_info)
return "OK"
except Exception as e:
LOGGER.error("Error processing task %s: %s", task_id, e, exc_info=True)
return "Internal server error", 500
if __name__ == '__main__':