Merge branch 'dev' into runny827

feat(training): 新增精益培训视频与周任务管理

# Conflicts:
#	backend/app/models/__init__.py
This commit is contained in:
runny committed 2026-09-08 18:30:09 +08:00
1 parent 85d27e9ffa
commit 91b7233872
812 files changed
+73763 -18908

No files matched your search

@@ -5,7 +5,8 @@ backend/app/services/schedule/scheduler_service.py
依赖:schedule_contract、job_params、cron_util、timezone_util、excel_service、wecom_notify、kb_sync。
逻辑:api/schedule/tasks.py 与 import_service 调用 create_task/update_task/enable_task;
job_params 在本层经 normalize_job_params_for_contract 唯一归一化(含切换 platform_api_path
未传参时重置默认值);schedule worker 调用 run_task_now 并经 resolve_schedule_executor 分发 handler。
未传参时重置默认值);schedule worker 调用 run_task_now 并经 resolve_schedule_executor 分发 handler;
handler 抛错时 failed_count=1、排程记 failed,并把 error= 打进 worker 日志。
"""
from __future__ import annotations
@@ -43,20 +44,16 @@ def request_cancel_run(run_id: int) -> None:
持久化取消指定排程运行,供 Web 与独立 worker 跨进程协作。
核心逻辑:将对应 queued/running 通用 Job 标记为 cancelled;执行器通过
ScheduleRun 状态/存在性复检停止可中断的长循环。
ScheduleRun 状态/存在性复检停止可中断的长循环。business_ref 兼容
`schedule_run:{id}` 与 `schedule_run:{id}:{platform_api_path}`。
"""
from app.jobs.types import JobType
from app.models import Job
from app.services.schedule.queue_service import query_jobs_for_schedule_run
now = datetime.utcnow()
jobs = (
db.session.query(Job)
.filter(
Job.domain == "schedule",
Job.job_type == JobType.SCHEDULE_RUN.value,
Job.business_ref == f"schedule_run:{int(run_id)}",
Job.status.in_(("queued", "running")),
)
query_jobs_for_schedule_run(run_id)
.filter(Job.status.in_(("queued", "running")))
.all()
)
for job in jobs:
@@ -493,6 +490,12 @@ def enable_task(task: ScheduleTask, *, commit: bool = True, check_options: bool
def run_task_now(task: ScheduleTask, *, trigger_type: str, triggered_by_user_id: int | None, run: ScheduleRun | None = None) -> ScheduleRun:
"""
立即执行一条排程并写入 ScheduleRun 终态。
核心逻辑:handler 未捕获异常记 failed_count=1,避免配置错误被标成 success;
该路径原先只写库不打日志,worker 汇总行看不到失败原因。
"""
recover_stale_awaiting_rpa_schedule_runs(task)
recover_stale_receipt_rpa_schedule_runs(task)
@@ -527,8 +530,16 @@ def run_task_now(task: ScheduleTask, *, trigger_type: str, triggered_by_user_id:
executor = resolve_schedule_executor(task)
total_count, success_count, failed_count, skipped_count, details, errors, step_logs = executor(task, run)
except Exception as exc:
total_count, success_count, failed_count, skipped_count, details, errors = 0, 0, 0, 0, [], [str(exc)]
total_count, success_count, failed_count, skipped_count, details, errors = 0, 0, 1, 0, [], [str(exc)]
step_logs = [{"step": "executor_error", "status": "failed", "detail": {"error": str(exc)}}]
if current_app:
current_app.logger.exception(
"[schedule-run] executor failed name=%s path=%s run_no=%s error=%s",
task.name,
task.platform_api_path,
run.run_no,
exc,
)
try:
db.session.refresh(run)
@@ -563,9 +574,18 @@ def run_task_now(task: ScheduleTask, *, trigger_type: str, triggered_by_user_id:
duration_ms = int((time.time() - start_ts) * 1000)
if current_app:
error_preview = "; ".join(str(item) for item in (errors or [])[:3])
current_app.logger.info(
"[schedule-run] run_no=%s total=%d success=%d failed=%d skipped=%d errors=%d",
run.run_no, total_count, success_count, failed_count, skipped_count, len(errors),
"[schedule-run] name=%s path=%s run_no=%s total=%d success=%d failed=%d skipped=%d errors=%d error=%s",
task.name,
task.platform_api_path,
run.run_no,
total_count,
success_count,
failed_count,
skipped_count,
len(errors or []),
error_preview or "-",
)
if total_count == 0 and not errors:
status = "success"