Merge pull request #60 from RuoJi6/fix/task-runtime-exclude-pause

fix: 运行时长排除暂停时间
This commit is contained in:
RuoJi6 authored and GitHub committed 2026-10-27 00:44:03 -07:00
commit cb0a69ef60
16 files changed
+587 -88

No files matched your search

+8 -12
View File
@@ -188,19 +188,15 @@ function fmtDuration(sec: number): string {
return `${s}s`;
}
// taskDuration is the task's run duration in seconds: created → now while running,
// created → completion for a finished task, else created → last activity. 0 when it
// never ran (no activity yet).
// taskDuration counts only active execution segments. A live segment ticks locally;
// paused, queued, and terminal tasks stay fixed at their persisted active total.
function taskDuration(task: Task, nowSec: number): number {
const start = task.created_unix ?? 0;
if (!start) return 0;
const end =
task.status === "running"
? nowSec
: task.completed_unix && task.completed_unix > 0
? task.completed_unix
: (task.last_activity_unix ?? 0);
return end > start ? end - start : 0;
const active = Math.max(0, Math.floor(task.active_run_seconds ?? 0));
const segmentStart = task.run_segment_started_unix ?? 0;
if (task.status === "running" && !task.paused && !task.queued && segmentStart > 0) {
return active + Math.max(0, Math.floor(nowSec - segmentStart));
}
return active;
}
// deleteDetails takes only the countable part of the result so callers can pass an
+12
View File
@@ -60,6 +60,9 @@ export const tasks: Task[] = [
status: "running",
created_at: T("2026-07-24T09:12:00Z"),
created_unix: 1785489120,
active_run_seconds: 28800,
run_segment_started_unix: 1785643102,
run_seconds: 28800,
last_activity: T("2026-07-26T03:58:22Z"),
last_activity_unix: 1785643102,
paused: false,
@@ -86,6 +89,9 @@ export const tasks: Task[] = [
status: "running",
created_at: T("2026-07-25T14:05:00Z"),
created_unix: 1785592500,
active_run_seconds: 14400,
run_segment_started_unix: 1785642010,
run_seconds: 14400,
last_activity: T("2026-07-26T03:40:10Z"),
last_activity_unix: 1785642010,
paused: false,
@@ -112,6 +118,9 @@ export const tasks: Task[] = [
status: "paused",
created_at: T("2026-07-22T08:30:00Z"),
created_unix: 1785313800,
active_run_seconds: 21600,
run_segment_started_unix: 0,
run_seconds: 21600,
last_activity: T("2026-07-23T18:40:10Z"),
last_activity_unix: 1785436810,
paused: true,
@@ -137,6 +146,9 @@ export const tasks: Task[] = [
status: "done",
created_at: T("2026-07-18T08:00:00Z"),
created_unix: 1784966400,
active_run_seconds: 86400,
run_segment_started_unix: 0,
run_seconds: 86400,
completed_at: T("2026-07-20T22:11:00Z"),
completed_unix: 1785190260,
last_activity: T("2026-07-20T22:11:00Z"),
+9
View File
@@ -951,6 +951,11 @@ function controlMockTask(id: string, action: "pause" | "resume"): BatchControlIt
task.queued = false;
task.status = "paused";
task.engine_mode = "paused";
if (task.run_segment_started_unix && task.run_segment_started_unix > 0) {
task.active_run_seconds = (task.active_run_seconds ?? 0) + Math.max(0, Math.floor(Date.now() / 1000) - task.run_segment_started_unix);
task.run_seconds = task.active_run_seconds;
}
task.run_segment_started_unix = 0;
} else {
if (!task.paused && task.status !== "paused") {
return { id, ok: false, status: task.status, error: "任务未暂停" };
@@ -959,6 +964,7 @@ function controlMockTask(id: string, action: "pause" | "resume"): BatchControlIt
task.queued = false;
task.status = "running";
task.engine_mode = "exploring";
task.run_segment_started_unix = Math.floor(Date.now() / 1000);
}
return { id, ok: true, status: task.status, queued: false };
}
@@ -1248,6 +1254,9 @@ function route(m: string, path: string, seg: string[], q: URLSearchParams, b: Re
status: "created",
created_at: now.toISOString(),
created_unix: Math.floor(now.getTime() / 1000),
active_run_seconds: 0,
run_segment_started_unix: 0,
run_seconds: 0,
paused: false,
active: true,
in_flight: 0,
+4 -1
View File
@@ -34,10 +34,13 @@ export interface Task {
goal: string;
status: TaskStatus;
created_at: string;
created_unix?: number; // created_at as unix seconds (run-duration calc)
created_unix?: number;
completed_at?: string; // RFC3339 finish time (done/failed); "" if unfinished
completed_unix?: number; // completed_at as unix seconds (0/undef if unfinished)
last_activity_unix?: number; // unix seconds of the last activity (0/undef if none)
run_seconds?: number; // backend-computed active runtime seconds
active_run_seconds?: number; // completed running segments in seconds
run_segment_started_unix?: number; // current running segment start; 0 when inactive
paused?: boolean;
queued?: boolean;
active?: boolean;