f7a4f26cf0
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>
1.5 KiB
1.5 KiB
name, kind, lang, domain, version, purity, signature, description, tags, uses_functions, uses_types, returns, returns_optional, error_type, imports, params, output, tested, tests, test_file_path, file_path
| name | kind | lang | domain | version | purity | signature | description | tags | uses_functions | uses_types | returns | returns_optional | error_type | imports | params | output | tested | tests | test_file_path | file_path | |||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| job_queue_create | function | go | infra | 1.0.0 | impure | func JobQueueCreate(db *sql.DB, tableName string) (*JobQueue, error) | Crea (o verifica) la tabla de jobs con indices en SQLite, activa WAL mode, y retorna un *JobQueue listo para usar. tableName puede ser cualquier identificador SQLite valido (default: 'jobs'). |
|
|
|
false | error_go_core |
|
|
puntero a JobQueue con DB y TableName configurados, listo para enqueue/dequeue | true |
|
functions/infra/job_queue_test.go | functions/infra/job_queue_create.go |
Ejemplo
db, _ := sql.Open("sqlite3", "jobs.db?_journal_mode=WAL")
q, err := JobQueueCreate(db, "jobs")
if err != nil {
log.Fatal(err)
}
// q esta listo para JobEnqueue, JobDequeue, etc.
Notas
Activa WAL mode en la DB. Usa CREATE TABLE IF NOT EXISTS y CREATE INDEX IF NOT EXISTS — es seguro llamarlo multiples veces. Indices creados: idx_{table}_dequeue (filtrado partial por status='pending'), idx_{table}_status, idx_{table}_type.