effectmq
Reference

Worker and Scheduler reference

Managed worker loops and durable cron materialization.

Worker.make

Worker.make(queue, handler, options?): Worker

Creates a descriptor without starting fibers or acquiring Redis connections.

OptionTypeDefault
concurrencynumber1
pollIntervalDuration.Input1 second
maintenanceIntervalDuration.Input1 second
drainTimeoutDuration.Input30 seconds
processingTaskQueue.ProcessingOptionsprocessing defaults

Concurrency is normalized with Math.max(1, Math.floor(value)).

Worker.run

Worker.run(worker): Effect<never, never, WorkerRequirements>

Runs acquisition slots and bounded maintenance until interrupted. Attempt and maintenance failures are logged and their loops continue. Interruption stops new acquisitions, waits for active handlers up to drainTimeout, then interrupts the remainder.

The worker checks its task definition before acquiring Redis roles or starting fibers. Invalid programmer-authored configuration is a defect.

The required environment includes RedisConnectionRoles, Crypto, queue retry services, handler services, payload decoding services, and terminal encoding services.

Scheduler.make

Scheduler.make(config): Scheduler

Creates a pure long-running Effect descriptor without evaluating it. Scheduler invariants are checked when the descriptor or materializeDue is executed.

FieldTypeDefaultDescription
namestringrequiredStable Redis schedule-cursor identity.
cronCron.CronrequiredCron expression and optional IANA time zone.
queueTaskQueuerequiredTarget queue.
payload(tick: Tick) => PayloadrequiredPayload constructor.
missedMissedTickPolicyrequiredDowntime selection policy.
startAtDatenext future tickInitial cursor for a new schedule.
taskOptionsrestricted TaskOptionsoffer defaultsCannot set taskId, onDuplicate, or retainResultUntil.

Scheduler is itself an Effect<void, SchedulerFailure, OfferRequirements>. It sleeps at least 100 milliseconds between observations.

MissedTickPolicy

TagBehavior
skipMaterializes no missed tasks and advances to the next future tick.
coalesceMaterializes one task for the most recent due tick.
backfillMaterializes up to maxBackfill recent due ticks in chronological order.

maxBackfill must be a positive safe integer. An invalid value is a defect at the first scheduler operation, not a typed scheduler failure.

Tick

FieldTypeDescription
scheduleNamestringStable scheduler name.
scheduledAtDateNominal cron instant used in task identity.
missedFromDateEarliest tick represented by this task.
missedToDateLatest tick represented by this task.

For ordinary and backfilled tasks, missedFrom and missedTo equal scheduledAt. A coalesced task spans the missed interval.

Scheduler.materializeDue

materializeDue(config, now?): Effect<Date, SchedulerFailure, ...>

Performs one bounded scheduler observation and returns the next cursor. The optional now supports deterministic tests; otherwise Effect's Clock is read when the Effect executes.

Each task id is <schedule-name>/<scheduledAt.toISOString()>. The task is offered before the cursor advances, and duplicate tick offers use return-existing.

On this page