mirror of
https://github.com/RuoJi6/ARTEX.git
synced 2026-10-27 17:03:49 +08:00
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.
26 lines
842 B
Go
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
|
|
}
|