fix: Calculate stale task count from heartbeat age
This commit is contained in:
@@ -615,15 +615,25 @@ class TaskService {
|
|||||||
return counts;
|
return counts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get counts by status, with stale calculated from running tasks with old heartbeats
|
||||||
const result = await pool.query(
|
const result = await pool.query(
|
||||||
`SELECT status, COUNT(*) as count
|
`SELECT
|
||||||
|
CASE
|
||||||
|
WHEN status IN ('running', 'claimed')
|
||||||
|
AND last_heartbeat_at < NOW() - INTERVAL '2 minutes'
|
||||||
|
THEN 'stale'
|
||||||
|
ELSE status
|
||||||
|
END as effective_status,
|
||||||
|
COUNT(*) as count
|
||||||
FROM worker_tasks
|
FROM worker_tasks
|
||||||
GROUP BY status`
|
GROUP BY effective_status`
|
||||||
);
|
);
|
||||||
|
|
||||||
for (const row of result.rows) {
|
for (const row of result.rows) {
|
||||||
const typedRow = row as { status: TaskStatus; count: string };
|
const typedRow = row as { effective_status: TaskStatus; count: string };
|
||||||
counts[typedRow.status] = parseInt(typedRow.count, 10);
|
if (typedRow.effective_status in counts) {
|
||||||
|
counts[typedRow.effective_status] = parseInt(typedRow.count, 10);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return counts;
|
return counts;
|
||||||
|
|||||||
Reference in New Issue
Block a user