Update task status handling to reset runner_id on job cancellation and failure
All checks were successful
Release Tag / release (push) Successful in 20s
All checks were successful
Release Tag / release (push) Successful in 20s
- Modified SQL queries in multiple functions to set runner_id to NULL when updating task statuses for cancelled jobs and failed tasks. - Ensured that tasks are properly marked as failed with the correct error messages and updated completion timestamps. - Improved handling of task statuses to prevent potential issues with task assignment and execution.
This commit is contained in:
@@ -944,7 +944,7 @@ func (s *Manager) handleCancelJob(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
// Cancel all pending tasks
|
// Cancel all pending tasks
|
||||||
_, err = conn.Exec(
|
_, err = conn.Exec(
|
||||||
`UPDATE tasks SET status = ? WHERE job_id = ? AND status = ?`,
|
`UPDATE tasks SET status = ?, runner_id = NULL WHERE job_id = ? AND status = ?`,
|
||||||
types.TaskStatusFailed, jobID, types.TaskStatusPending,
|
types.TaskStatusFailed, jobID, types.TaskStatusPending,
|
||||||
)
|
)
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -390,7 +390,7 @@ func (s *Manager) handleNextJob(w http.ResponseWriter, r *http.Request) {
|
|||||||
t.condition
|
t.condition
|
||||||
FROM tasks t
|
FROM tasks t
|
||||||
JOIN jobs j ON t.job_id = j.id
|
JOIN jobs j ON t.job_id = j.id
|
||||||
WHERE t.status = ? AND j.status != ?
|
WHERE t.status = ? AND t.runner_id IS NULL AND j.status != ?
|
||||||
ORDER BY t.created_at ASC
|
ORDER BY t.created_at ASC
|
||||||
LIMIT 50`,
|
LIMIT 50`,
|
||||||
types.TaskStatusPending, types.JobStatusCancelled,
|
types.TaskStatusPending, types.JobStatusCancelled,
|
||||||
@@ -1363,7 +1363,7 @@ func (s *Manager) handleRunnerJobWebSocket(w http.ResponseWriter, r *http.Reques
|
|||||||
log.Printf("Job WebSocket disconnected unexpectedly for task %d, marking as failed", taskID)
|
log.Printf("Job WebSocket disconnected unexpectedly for task %d, marking as failed", taskID)
|
||||||
s.db.With(func(conn *sql.DB) error {
|
s.db.With(func(conn *sql.DB) error {
|
||||||
_, err := conn.Exec(
|
_, err := conn.Exec(
|
||||||
`UPDATE tasks SET status = ?, error_message = ?, completed_at = ? WHERE id = ?`,
|
`UPDATE tasks SET status = ?, runner_id = NULL, error_message = ?, completed_at = ? WHERE id = ?`,
|
||||||
types.TaskStatusFailed, "WebSocket connection lost", time.Now(), taskID,
|
types.TaskStatusFailed, "WebSocket connection lost", time.Now(), taskID,
|
||||||
)
|
)
|
||||||
return err
|
return err
|
||||||
@@ -1678,11 +1678,10 @@ func (s *Manager) handleWebSocketTaskComplete(runnerID int64, taskUpdate WSTaskU
|
|||||||
} else {
|
} else {
|
||||||
// No retries remaining - mark as failed
|
// No retries remaining - mark as failed
|
||||||
err = s.db.WithTx(func(tx *sql.Tx) error {
|
err = s.db.WithTx(func(tx *sql.Tx) error {
|
||||||
_, err := tx.Exec(`UPDATE tasks SET status = ? WHERE id = ?`, types.TaskStatusFailed, taskUpdate.TaskID)
|
_, err := tx.Exec(
|
||||||
if err != nil {
|
`UPDATE tasks SET status = ?, runner_id = NULL, completed_at = ? WHERE id = ?`,
|
||||||
return err
|
types.TaskStatusFailed, now, taskUpdate.TaskID,
|
||||||
}
|
)
|
||||||
_, err = tx.Exec(`UPDATE tasks SET completed_at = ? WHERE id = ?`, now, taskUpdate.TaskID)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -1849,7 +1848,7 @@ func (s *Manager) cancelActiveTasksForJob(jobID int64) error {
|
|||||||
// Tasks don't have a cancelled status - mark them as failed instead
|
// Tasks don't have a cancelled status - mark them as failed instead
|
||||||
err := s.db.With(func(conn *sql.DB) error {
|
err := s.db.With(func(conn *sql.DB) error {
|
||||||
_, err := conn.Exec(
|
_, err := conn.Exec(
|
||||||
`UPDATE tasks SET status = ?, error_message = ? WHERE job_id = ? AND status IN (?, ?)`,
|
`UPDATE tasks SET status = ?, runner_id = NULL, error_message = ? WHERE job_id = ? AND status IN (?, ?)`,
|
||||||
types.TaskStatusFailed, "Job cancelled", jobID, types.TaskStatusPending, types.TaskStatusRunning,
|
types.TaskStatusFailed, "Job cancelled", jobID, types.TaskStatusPending, types.TaskStatusRunning,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user