Skip to content

Queues

queue.Module(queue.Options{Driver: asynq.New(asynq.RedisClientOpt{Addr: "localhost:6379"})}) // or the memory default
func (m *Mailer) Process(r *queue.Registry) {
queue.Handle(r, "welcome-email", m.send) // func(ctx, WelcomeEmail) error
}
id, err := q.Add(ctx, "welcome-email", WelcomeEmail{UserID: u.ID},
queue.Delay(time.Minute), queue.Attempts(5), queue.ID("welcome:"+u.ID))

A handler error retries the job with backoff; wrap it with queue.SkipRetry to fail at once. queue.JobFrom(ctx) gives the job’s ID and attempt. Set NoWorker in a process that only produces jobs. The memory driver loses jobs on restart; use it in development and tests (mem.Wait(ctx) waits until no job is pending).