fix: Use database task counts for Completed/Failed stats on Workers page
This commit is contained in:
@@ -785,6 +785,7 @@ export function WorkersDashboard() {
|
|||||||
const [tasks, setTasks] = useState<Task[]>([]); // Running tasks
|
const [tasks, setTasks] = useState<Task[]>([]); // Running tasks
|
||||||
const [recentTasks, setRecentTasks] = useState<Task[]>([]); // Recent completed/failed
|
const [recentTasks, setRecentTasks] = useState<Task[]>([]); // Recent completed/failed
|
||||||
const [pendingTaskCount, setPendingTaskCount] = useState<number>(0);
|
const [pendingTaskCount, setPendingTaskCount] = useState<number>(0);
|
||||||
|
const [taskCounts, setTaskCounts] = useState<{ completed: number; failed: number }>({ completed: 0, failed: 0 });
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|
||||||
@@ -820,6 +821,10 @@ export function WorkersDashboard() {
|
|||||||
setRecentTasks(combined.slice(0, 15));
|
setRecentTasks(combined.slice(0, 15));
|
||||||
|
|
||||||
setPendingTaskCount(countsRes.data?.pending || 0);
|
setPendingTaskCount(countsRes.data?.pending || 0);
|
||||||
|
setTaskCounts({
|
||||||
|
completed: countsRes.data?.completed || 0,
|
||||||
|
failed: countsRes.data?.failed || 0,
|
||||||
|
});
|
||||||
setError(null);
|
setError(null);
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
console.error('Fetch error:', err);
|
console.error('Fetch error:', err);
|
||||||
@@ -897,8 +902,9 @@ export function WorkersDashboard() {
|
|||||||
const activeWorkers = workers.filter(w => w.status !== 'offline' && w.status !== 'terminated');
|
const activeWorkers = workers.filter(w => w.status !== 'offline' && w.status !== 'terminated');
|
||||||
const busyWorkers = workers.filter(w => w.current_task_id !== null);
|
const busyWorkers = workers.filter(w => w.current_task_id !== null);
|
||||||
const idleWorkers = activeWorkers.filter(w => w.current_task_id === null);
|
const idleWorkers = activeWorkers.filter(w => w.current_task_id === null);
|
||||||
const totalCompleted = workers.reduce((sum, w) => sum + w.tasks_completed, 0);
|
// Use task counts from database (survives worker restarts)
|
||||||
const totalFailed = workers.reduce((sum, w) => sum + w.tasks_failed, 0);
|
const totalCompleted = taskCounts.completed;
|
||||||
|
const totalFailed = taskCounts.failed;
|
||||||
|
|
||||||
// Get task info for a worker
|
// Get task info for a worker
|
||||||
const getWorkerTask = (workerId: string): Task | undefined => {
|
const getWorkerTask = (workerId: string): Task | undefined => {
|
||||||
|
|||||||
Reference in New Issue
Block a user