b5a867ca5a
Implementa el subsistema completo de background jobs para apps Go en el dominio infra. 9 funciones + 3 tipos + 17 tests, todos pasando. - Tipos: Job (product), JobQueue (product), JobStatus (sum) con JobHandler, EnqueueOption y WorkerOption usando functional options pattern - job_queue_create: CREATE TABLE + indices + WAL mode - job_enqueue: INSERT con UUID (github.com/google/uuid), WithPriority/WithScheduledAt/WithMaxAttempts - job_dequeue: SELECT+UPDATE atomico en transaccion exclusiva, filtro por jobTypes - job_complete / job_fail: transiciones de estado; fail → dead cuando attempts >= max_attempts - job_status_summary: pura, formatea conteo de jobs por estado - job_worker: poll loop bloqueante, context-cancelable, graceful shutdown - job_worker_pool: N workers con golang.org/x/sync/errgroup - job_cleanup: DELETE jobs terminales mas viejos que olderThan Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
20 lines
636 B
Go
20 lines
636 B
Go
package infra
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
// JobStatus formats a map of status → count into a human-readable summary string.
|
|
// Example output: "pending: 5, running: 2, completed: 10, failed: 1, dead: 0"
|
|
// The output always includes all five canonical statuses in a fixed order.
|
|
// This is a pure function — no I/O, no state.
|
|
func JobStatusSummary(counts map[string]int) string {
|
|
statuses := []string{"pending", "running", "completed", "failed", "dead"}
|
|
parts := make([]string, 0, len(statuses))
|
|
for _, s := range statuses {
|
|
parts = append(parts, fmt.Sprintf("%s: %d", s, counts[s]))
|
|
}
|
|
return strings.Join(parts, ", ")
|
|
}
|