fix: Delete completed tasks from pool instead of marking complete
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
Completed tasks are now deleted from worker_tasks table. Only failed tasks remain in the pool for retry/review. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -261,28 +261,24 @@ class TaskService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mark a task as completed with verification
|
* Mark a task as completed and remove from pool
|
||||||
* Returns true if completion was verified in DB, false otherwise
|
* Completed tasks are deleted - only failed tasks stay in the pool for retry/review
|
||||||
|
* Returns true if task was successfully deleted
|
||||||
*/
|
*/
|
||||||
async completeTask(taskId: number, result?: Record<string, unknown>): Promise<boolean> {
|
async completeTask(taskId: number, result?: Record<string, unknown>): Promise<boolean> {
|
||||||
await pool.query(
|
// Delete the completed task from the pool
|
||||||
`UPDATE worker_tasks
|
// Only failed tasks stay in the table for retry/review
|
||||||
SET status = 'completed', completed_at = NOW(), result = $2, error_message = NULL
|
const deleteResult = await pool.query(
|
||||||
WHERE id = $1`,
|
`DELETE FROM worker_tasks WHERE id = $1 RETURNING id`,
|
||||||
[taskId, result ? JSON.stringify(result) : null]
|
|
||||||
);
|
|
||||||
|
|
||||||
// Verify completion was recorded
|
|
||||||
const verify = await pool.query(
|
|
||||||
`SELECT status FROM worker_tasks WHERE id = $1`,
|
|
||||||
[taskId]
|
[taskId]
|
||||||
);
|
);
|
||||||
|
|
||||||
if (verify.rows[0]?.status !== 'completed') {
|
if (deleteResult.rowCount === 0) {
|
||||||
console.error(`[TaskService] Task ${taskId} completion NOT VERIFIED - DB shows status: ${verify.rows[0]?.status}`);
|
console.error(`[TaskService] Task ${taskId} completion FAILED - task not found or already deleted`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(`[TaskService] Task ${taskId} completed and removed from pool`);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user