---
name: job_enqueue
kind: function
lang: go
domain: infra
version: "1.0.0"
purity: impure
signature: "func JobEnqueue(q *JobQueue, jobType string, payload string, opts ...EnqueueOption) (string, error)"
description: "Inserta un nuevo job en la cola con UUID generado, tipo, payload JSON y opciones. Retorna el UUID del job. Opciones: WithPriority, WithScheduledAt, WithMaxAttempts."
tags: [job, queue, enqueue, insert, async, background, infra, sqlite, pendiente-usar]
uses_functions: []
uses_types: [job_queue_go_infra]
returns: []
returns_optional: false
error_type: "error_go_core"
imports: [fmt, time, github.com/google/uuid]
params:
  - name: q
    desc: "cola de jobs creada con JobQueueCreate"
  - name: jobType
    desc: "identificador del tipo de trabajo (ej: 'send_email', 'resize_image')"
  - name: payload
    desc: "JSON string con los datos del job; si vacio se usa '{}'"
  - name: opts
    desc: "opciones: WithPriority(n), WithScheduledAt(t), WithMaxAttempts(n)"
output: "UUID del job insertado como string"
tested: true
tests:
  - "enqueue_dequeue_atomicidad"
  - "dequeue_priority_order"
  - "dequeue_jobtype_filter"
  - "dequeue_scheduled_in_future_waits"
test_file_path: "functions/infra/job_queue_test.go"
file_path: "functions/infra/job_enqueue.go"
---

## Ejemplo

```go
id, err := JobEnqueue(q, "send_email", `{"to":"user@example.com"}`,
    WithPriority(5),
    WithMaxAttempts(5),
)
```

## Notas

Usa `github.com/google/uuid` para generar el ID. El payload por defecto es "{}". El campo `scheduled_at` por defecto es `time.Now().UTC()`. La prioridad mas alta se procesa primero (ORDER BY priority DESC).
