Skip to content

Fase 3.1: Retry + Error Handling

← Fase 2.2 | Siguiente: 3.2 Monitoring →


Agregar columnas retry a background_jobs

Archivo: */backend/background-jobs-system.md

Rama: feature/background-jobs-retry

Fase: 3.1: Retry + Error Handling

Estimación: 2 horas

Dependencias: Todas tareas Fase 2

Deliverables

  • [ ] Crear migración: ALTER TABLE background_jobs ADD COLUMN retry_count INT DEFAULT 0, ADD COLUMN max_retries INT DEFAULT 3
  • [ ] Índice en (status, retry_count)
  • [ ] DTO actualizada
  • [ ] Model getter/setter para retry
  • [ ] Ejecutar y validar

Implementar retry logic con exponential backoff

Archivo: */backend/background-jobs-system.md

Rama: feature/background-jobs-retry

Fase: 3.1: Retry + Error Handling

Estimación: 5 horas

Dependencias: Agregar columnas retry

Deliverables

  • [ ] Crear server/src/services/BackgroundJobs/RetryStrategy.php
    • [ ] Exponential backoff: delay = base * (2 ^ attempt), max 3600s
    • [ ] Método calculateNextAttempt(retryCount): DateTime
  • [ ] Modificar JobRunner
    • [ ] En fallan: si retry_count < max_retries → status pending, delay próxima ejecución
    • [ ] En fallan: si retry_count >= max_retries → status failed
    • [ ] Log cada reintento
  • [ ] Unit tests: exponential backoff
  • [ ] Integration tests: retry flow
  • [ ] Tests: max retries exceeded

Crear cronjob para cleanup stale jobs

Archivo: */backend/background-jobs-system.md

Rama: feature/background-jobs-cleanup

Fase: 3.1: Retry + Error Handling

Estimación: 3 horas

Dependencias: Implementar retry logic

Deliverables

  • [ ] Crear CLI script server/bin/cleanup-stale-jobs.php
    • [ ] Ejecutable cada 1 hora
    • [ ] Deleta completed/failed jobs > 30 días
    • [ ] Logging de registros borrados
    • [ ] Parámetro --dry-run
  • [ ] Crear SystemD timer (o crontab entry)
    • [ ] Cron: 0 * * * * (cada hora)
  • [ ] Tests simulando cleanup
  • [ ] Tests parámetro --dry-run

Crear admin endpoint para failed jobs

Archivo: */backend/background-jobs-system.md

Rama: feature/background-jobs-admin

Fase: 3.1: Retry + Error Handling

Estimación: 4 horas

Dependencias: Crear cronjob cleanup

Deliverables

  • [ ] Crear server/src/controller/modulo-background-jobs/AdminJobController.php
    • [ ] GET /admin/jobs/failed (lista failed jobs)
    • [ ] GET /admin/jobs/failed/:id (detalle)
    • [ ] POST /admin/jobs/failed/:id/retry (reintentar)
    • [ ] DELETE /admin/jobs/failed/:id (eliminar)
    • [ ] Filters: status, schema, created_date_range
    • [ ] Pagination
  • [ ] Admin permission middleware
  • [ ] Create routes /admin/jobs/*
  • [ ] Unit tests
  • [ ] Integration tests

← Fase 2.2 | Siguiente: 3.2 Monitoring →