Skip to content

Fase 2.1: SSE Endpoint con PostgreSQL NOTIFY

← Fase 1.4 | Siguiente: 2.2 Progress →


Crear JobStreamController (SSE)

Archivo: */architecture/background-jobs-architecture.md

Rama: feature/background-jobs-sse

Fase: 2.1: SSE Endpoint con PostgreSQL NOTIFY

Estimación: 5 horas

Dependencias: Todas tareas Fase 1

Deliverables

  • [ ] Crear server/src/controller/modulo-background-jobs/JobStreamController.php
    • [ ] GET /jobs/:id/stream (SSE endpoint)
    • [ ] Header Content-Type: text/event-stream
    • [ ] Long-polling fallback si SSE no soportado
    • [ ] Auth middleware (JWT)
    • [ ] 30-segundo timeout
    • [ ] Graceful disconnect handling
  • [ ] Eventos SSE: status_changed, progress_updated
  • [ ] Tests simulando SSE
  • [ ] Tests fallback mode

Modificar worker para emitir NOTIFY

Archivo: */architecture/background-jobs-architecture.md

Rama: feature/background-jobs-sse

Fase: 2.1: SSE Endpoint con PostgreSQL NOTIFY

Estimación: 4 horas

Dependencias: Crear JobStreamController

Deliverables

  • [ ] Modificar server/src/services/BackgroundJobs/JobRunner.php
    • [ ] Al cambiar status, ejecutar: NOTIFY background_jobs_channel, jsonPayload
    • [ ] Canal específico por schema: suc0001_background_jobs
    • [ ] Payload:
  • [ ] Unit tests verificando NOTIFY
  • [ ] Integration tests con listener
  • [ ] Verificar no hay race conditions

Frontend: Crear hook useJobStream

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

Rama: feature/background-jobs-sse-client

Fase: 2.1: SSE Endpoint con PostgreSQL NOTIFY

Estimación: 4 horas

Dependencias: Crear JobStreamController

Deliverables

  • [ ] Crear public/src/backgroundJobs/hooks/useJobStream.ts
    • [ ] EventSource con URL /jobs/:id/stream
    • [ ] Auto-reconnect con exponential backoff
    • [ ] Fallback a polling si no SSE
    • [ ] useEffect cleanup para cerrar conexión
    • [ ] Callback onStatusChange
  • [ ] TypeScript types para eventos
  • [ ] Tests con mock EventSource
  • [ ] Tests fallback a polling

← Fase 1.4 | Siguiente: 2.2 Progress →