Skip to content

fix: 运行时长排除暂停时间 - #60

Merged
RuoJi6 merged 2 commits into
mainfrom
fix/task-runtime-exclude-pause
Oct 27, 2026
Merged

RuoJi6 merged 2 commits into
mainfrom
fix/task-runtime-exclude-pause

Conversation

@RuoJi6

@RuoJi6 RuoJi6 commented Oct 27, 2026

Copy link
Copy Markdown
Owner

Summary

修复任务列表「运行时长」在暂停后再运行时把暂停时间也算进去的问题:只累计实际 running 时间。

Root cause

前端 taskDuration 与编排 list_tasks 使用「创建时间 → 现在/最后活动」墙钟,未扣除 pause / 排队等待。

Fix

  • 新增 tasks.active_run_seconds、run_segment_started_at
  • 真正执行时 Start segment;暂停 / 入队 / 终态 Finalize 并折入累计
  • DTO 暴露 run_seconds / active_run_seconds / run_segment_started_unix
  • 前端按 active + 当前 segment 本地 tick;paused/queued/terminal 不再增长
  • 进程启动 ClearOpenTaskRunSegments:不把停机时间算进运行时长
  • 终态/暂停成功后立即镜像内存时钟

Test plan

  • go test ./server -run 'TaskRun|Runtime|Pause|Admission'
  • go test ./db -run 'RunSegment|Runtime|Paused|Status|ClearOpen'(含生命周期)
  • ./build.sh
  • UI:创建任务 → 跑一会儿 → 暂停一段时间 → 恢复 → 确认「运行时长」未包含暂停段

Notes

  • 升级后无历史回填:旧任务从 0 起算新语义;正在跑的任务重启后从引擎再次 Start 起重新计段
  • 任务超时 first_run_at / deadline_at 语义未改(仍为墙钟)

artex added 2 commits October 27, 2026 13:37
Persist active_run_seconds + run_segment_started_at so task list and
orchestration list_tasks accumulate only actual execution time across
pause/resume/queue/terminal transitions.
Clear open run segments on process start without imputing downtime.
Mirror terminal/pause runtime fields into memory before hydration, make
SetPaused finalize segments, and add DB lifecycle tests.
@RuoJi6
RuoJi6 merged commit cb0a69e into main Oct 27, 2026
@RuoJi6
RuoJi6 deleted the fix/task-runtime-exclude-pause branch October 27, 2026 07:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant