You've already forked FrameTour-RenderWorker
mypy
This commit is contained in:
23
app.py
23
app.py
@@ -21,48 +21,51 @@ LOGGER = logging.getLogger(__name__)
|
||||
init_opentelemetry(batch=False)
|
||||
app = flask.Flask(__name__)
|
||||
|
||||
@app.get('/health/check')
|
||||
|
||||
@app.get("/health/check")
|
||||
def health_check():
|
||||
return api.sync_center()
|
||||
|
||||
@app.post('/')
|
||||
|
||||
@app.post("/")
|
||||
def do_nothing():
|
||||
return "NOOP"
|
||||
|
||||
@app.post('/<task_id>')
|
||||
|
||||
@app.post("/<task_id>")
|
||||
def do_task(task_id):
|
||||
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__':
|
||||
if __name__ == "__main__":
|
||||
app.run(host="0.0.0.0", port=9998)
|
||||
|
||||
Reference in New Issue
Block a user