Skip to main content

Worker configuration

A FlareWorker is configured entirely through its constructor.

import { FlareWorker } from "@zeridion/flare/worker";

const worker = new FlareWorker({
apiKey: process.env.FLARE_API_KEY,
baseUrl: "https://api.zeridion.com",
concurrency: 5,
jobs: [sendWelcome, nightlyCleanup],
logger: console,
});

Credentials

Supply either an apiKey (the worker builds its own client) or a pre-built client:

OptionTypeDescription
apiKeystringYour Zeridion API key. Falls back to the FLARE_API_KEY environment variable when omitted.
baseUrlstringAPI base URL. Defaults to https://api.zeridion.com. Point it at a local or dev API as needed.
clientFlareClientA configured client to reuse (its credential, base URL, and body cap are inherited).

The worker derives a dedicated connection for polling tuned for the long-poll — a poll read-timeout above the server's polling window, so a long-poll is never cut short — and reuses pooled connections across the loop.

Jobs

OptionTypeDescription
jobsJobDefinition[]The defineJob / defineRecurringJob results to run. Required. An empty array makes start() a no-op.

Concurrency and polling

OptionTypeDefaultDescription
concurrencynumber10Maximum jobs run at once. Reported to the server as available capacity (clamped to the server's accepted range).
queuesstring[]["default"]Queues to poll. Every registered job's queue is added automatically.
pollIntervalMsnumber2000Idle delay between polls when no jobs are returned.
pollTimeoutMsnumber35000Read timeout for a single long-poll request. Keep it above the server's polling window.
pollMaxRetriesnumber2Bounded retry budget for a failed poll, so a transient-error storm cannot exceed the poll window.

The worker reports its free slots as capacity on every poll and never starts more jobs than it has slots for, so the server hands it only what it can run.

Graceful shutdown

OptionTypeDefaultDescription
gracePeriodMsnumber25000How long stop() waits for in-flight jobs to finish before resolving.

On stop() (or a SIGTERM / SIGINT when started via run()), the worker stops polling, signals in-flight jobs to wind down via their cancellation signal, and waits up to gracePeriodMs for them to finish. Keep the grace window under your platform's own shutdown grace so handlers get a chance to drain before the process is force-killed.

Identity

OptionTypeDescription
hostnamestringOverride the reported hostname (otherwise the machine hostname).
workerIdstringOverride the generated worker id.

By default the worker id is wrk_{host}_{pid}_{random} — the host segment sanitized to the characters the server accepts, the random segment from a cryptographic source so ids never collide across containers.

Logging

OptionTypeDescription
loggerLoggerA structural logger (debug / info / warn / error). console satisfies it. Omit for a silent default.

The library never logs to a global and never logs raw payloads or credentials. Job handlers receive a logger pre-bound with the job's id, type, and attempt — see job context.

See also