Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/__tests__/scheduler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function makePool(): WorktreePool {
function makeRunner(): AgentRunner {
return {
run: async (task: Task) => { task.status = "success"; task.durationMs = 100; return task; },
getRunningTasks: () => [],
} as unknown as AgentRunner;
}

Expand Down
22 changes: 20 additions & 2 deletions src/scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,29 @@ export class Scheduler {
}

getTask(id: string): Task | undefined {
return this.tasks.get(id) ?? this.store.get(id) ?? undefined;
const task = this.tasks.get(id) ?? this.store.get(id) ?? undefined;
if (task?.status === "running" && task.startedAt) {
task.durationMs = Date.now() - new Date(task.startedAt).getTime();
const runningInfo = this.runner.getRunningTasks();
const live = runningInfo.find(r => r.id === task.id);
if (live) task.costUsd = live.costUsd;
}
return task;
}

listTasks(): Task[] {
return [...this.tasks.values()];
const tasks = [...this.tasks.values()];
const now = Date.now();
const runningInfo = this.runner.getRunningTasks();
const runningMap = new Map(runningInfo.map(r => [r.id, r]));
for (const t of tasks) {
if (t.status === "running" && t.startedAt) {
t.durationMs = now - new Date(t.startedAt).getTime();
const live = runningMap.get(t.id);
if (live) t.costUsd = live.costUsd;
}
}
return tasks;
}

getQueuePosition(taskId: string): number {
Expand Down