Merge branch 'dev' of https://gitee.com/justop/hxops into dev
This commit is contained in:
commit
ac04409e79
12 files changed
+292
-76
No files matched your search
@@ -69,6 +69,20 @@ def delete_schedule(task_id: int):
|
||||
task = db.session.get(ScheduleTask, task_id)
|
||||
if not task:
|
||||
return jsonify({'error': 'Not found'}), 404
|
||||
|
||||
from app.services.schedule.scheduler_service import request_cancel_run
|
||||
running_runs = db.session.query(ScheduleRun).filter(
|
||||
ScheduleRun.schedule_task_id == task_id,
|
||||
ScheduleRun.status == "running",
|
||||
).all()
|
||||
for rr in running_runs:
|
||||
request_cancel_run(rr.id)
|
||||
rr.status = "failed"
|
||||
rr.error_message = "排程已被删除,执行中断"
|
||||
rr.finished_at = datetime.utcnow()
|
||||
if running_runs:
|
||||
db.session.commit()
|
||||
|
||||
runs = db.session.query(ScheduleRun).filter(ScheduleRun.schedule_task_id == task_id).all()
|
||||
for r in runs:
|
||||
if r.excel_file_path:
|
||||
@@ -122,6 +136,13 @@ def run_schedule(task_id: int):
|
||||
return jsonify({'error': 'Not found'}), 404
|
||||
user = get_current_user()
|
||||
|
||||
existing = db.session.query(ScheduleRun).filter(
|
||||
ScheduleRun.schedule_task_id == task.id,
|
||||
ScheduleRun.status == "running",
|
||||
).first()
|
||||
if existing:
|
||||
return jsonify({'error': '该排程正在执行中,请等待完成后再试', 'run_id': existing.id}), 409
|
||||
|
||||
run = ScheduleRun(
|
||||
run_no=_generate_run_no(),
|
||||
schedule_task_id=task.id,
|
||||
|
||||
Reference in new issue
Block a user