Files
ARTEX-chixuweihu/server/task_runtime.go
T
artex 41c967f7ad fix: exclude pause time from task run duration
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.
2026-10-27 13:37:43 +08:00

26 lines
842 B
Go

package server
// taskRunSeconds computes displayed active runtime from persisted segment data.
// Segment timestamps are unix seconds; a zero start means no active segment.
func taskRunSeconds(active, segmentStarted, now int64, status string, paused, queued bool) int64 {
if active < 0 {
active = 0
}
if status == "running" && !paused && !queued && segmentStarted > 0 && now > segmentStarted {
return active + now - segmentStarted
}
return active
}
// finalizeTaskRunSeconds mirrors the database transition for deterministic unit
// tests and callers that need to reason about a segment without a live database.
func finalizeTaskRunSeconds(active, segmentStarted, now int64) (int64, int64) {
if active < 0 {
active = 0
}
if segmentStarted > 0 && now > segmentStarted {
active += now - segmentStarted
}
return active, 0
}