v1.1.3

Enqueue Options

Last updated


This page lists the four EnqueueOption functions that adjust a single task's ID, timeout, success callback, and retries.

EnqueueOption


  1. type EnqueueOption func(*enqueueConfig)
  2. func WithTaskID(id string) EnqueueOption
  3. func WithTimeout(d time.Duration) EnqueueOption
  4. func WithCallback(fn func(id string)) EnqueueOption
  5. func WithRetry(retryMax ...int) EnqueueOption

OptionWithout ItWith It
WithTaskIDGenerates a UUID v4Uses the given ID; duplicates are not checked
WithTimeoutDerived from the preset and clamped to 15–120sUses d as-is
WithCallbackNoneCalled with the task ID in a new goroutine after success
WithRetryFails once and stopsUp to 3 retries with no argument; up to n retries with WithRetry(n)

Options apply in order; when the same option is passed more than once, the last one wins.

Common Needs


NeedOption
Custom task IDcore.WithTaskID("order-1001")
One-off timeout (not clamped to 15–120s)core.WithTimeout(5 * time.Minute)
Notify on successcore.WithCallback(func(id string) { ... })
Retry on failurecore.WithRetry() or core.WithRetry(5)

  1. id, err := q.Enqueue(ctx, "email", sendEmail,
  2. core.WithTaskID("order-1001"),
  3. core.WithRetry(5),
  4. core.WithCallback(func(id string) { log.Println("done", id) }),
  5. )

Priority cannot be set per task; it comes from the preset, see Presets. Retry behavior in detail: Execution and Retries.
中文