Worker configuration
A worker is configured with worker.Options, passed to worker.NewWorker. The
zero value is valid — every unset field falls back to a sensible default.
w := worker.NewWorker(client, worker.Options{
Queues: []string{"default", "emails"},
Concurrency: 10,
PollInterval: 2 * time.Second,
DefaultTimeout: 30 * time.Minute,
DefaultMaxAttempts: 3,
ShutdownTimeout: 0, // unbounded drain
Logger: slog.Default(),
})
Options
| Field | Type | Default | Meaning |
|---|---|---|---|
Queues | []string | ["default"] | Queues the worker polls. |
Concurrency | int | 10 | Maximum jobs processed simultaneously. |
PollInterval | time.Duration | 2s | Idle delay between polls when no work is returned or all slots are busy. |
DefaultTimeout | time.Duration | 30m | Per-job deadline when a job carries none. |
DefaultMaxAttempts | int | 3 | Attempts announced for a handler that does not set its own. |
ShutdownTimeout | time.Duration | 0 (unbounded) | Upper bound on the graceful drain. Zero waits for every in-flight job. |
Hostname | string | OS hostname | Overrides the host portion of the worker id and the announced hostname. |
Logger | *slog.Logger | slog.Default() | Runtime logger. Handler logs use a copy bound with job fields. |
Concurrency and capacity
Concurrency is the hard cap on simultaneous handlers. On each poll the worker
reports its free slot count as capacity, so the server never hands out more
jobs than the worker can run. Reported capacity is bounded to the range 1–50.
When every slot is busy, the worker idles for PollInterval instead of polling.
The HTTP client
The worker reuses the flare.Client you pass to NewWorker as its transport
(authentication, retries, and the response-size cap all come from it). Build that
client for long-polling:
client, _ := flare.NewClient(flare.WithHTTPClient(worker.NewPollHTTPClient()))
worker.NewPollHTTPClient() returns an *http.Client with no total timeout
and a response-header timeout above the long-poll window. This matters: the poll
holds a connection open for roughly 30 seconds waiting for work, so a short total
client timeout would abort it mid-poll. Per-job deadlines flow through the
handler's context instead, not the HTTP client.
If you supply your own client with a short non-zero total timeout, NewWorker
logs a warning at startup.
Job type configuration
Per-job-type settings (queue, attempts, timeout, cron) live on the handler
registration, not on Options. See Handlers and
Recurring jobs.
Environment
FLARE_API_KEY— used by the client when you do not pass an explicit key.