--- name: job_fail kind: function lang: go domain: infra version: "1.0.0" purity: impure signature: "func JobFail(q *JobQueue, jobID string, errMsg string) error" description: "Incrementa el contador de intentos y transiciona el job a 'failed' (reintentable) o 'dead' (sin mas intentos) segun si attempts >= max_attempts. Almacena el mensaje de error." tags: [job, queue, fail, retry, dead, sqlite, async, background, infra] uses_functions: [] uses_types: [job_queue_go_infra] returns: [] returns_optional: false error_type: "error_go_core" imports: [fmt, time] params: - name: q desc: "cola de jobs creada con JobQueueCreate" - name: jobID desc: "UUID del job que fallo" - name: errMsg desc: "mensaje de error para almacenar en la columna error" output: "error si el job no existe o falla el UPDATE" tested: true tests: - "fail_increments_attempts" - "fail_transitions_to_dead" test_file_path: "functions/infra/job_queue_test.go" file_path: "functions/infra/job_fail.go" --- ## Ejemplo ```go if err := handler(job); err != nil { _ = JobFail(q, job.ID, err.Error()) } ``` ## Notas El UPDATE es atomico: incrementa attempts y decide el nuevo status en un solo SQL con CASE WHEN. Si `(attempts + 1) >= max_attempts` → status='dead', sino → status='failed'. Los jobs failed pueden ser reintentados manualmente reseteando su status a 'pending'. Los jobs dead no se procesan automaticamente.