Effect
Use MonqueEffect from @monque/core/effect. Its scoped Layer borrows db;
close your MongoDB connection after the scheduler scope finishes. Core includes
Effect 4 and needs no OpenTelemetry SDK.
Register and start Workers
Section titled “Register and start Workers”Pass a setup callback as the third argument to MonqueEffect.layer to register
Workers and start processing. Setup resources are available until scheduler
disposal and Worker cleanup finish.
Run the returned Effect once at your application entry point. Interrupting it starts scoped cleanup. Registration captures the supplied application services; keep them alive until Monque is disposed. Provide resource Layers to the scheduler Layer, as above. Acquire per-attempt resources in the Worker handler.
For producers, MonqueEffect.layer(db, options) initializes without starting
processing. You can register and start explicitly later. For a host needing
Management or EventEmitter access, use Monque.scoped(db, options) and call native
operations through monque.effects. See the
complete host example.
Operations and failures
Section titled “Operations and failures”The service exposes enqueue, enqueueMany, now, schedule, all public Job
management and read methods, pause, resume, isPaused, getProcessingState,
start, stop, isHealthy, and dispose. Controls without arguments are Effects
(yield* scheduler.start); methods with arguments return Effects. Acquisition
initializes the scheduler. stop permits a later start; dispose is terminal.
Expected operation failures use the MonqueError channel. Recover from validation
and state errors with instanceof InvalidCronError, JobStateError, or another
public error. Database failures use ConnectionError with the underlying error
in cause.
Worker failures follow the configured retry policy. NonRetryableError skips retries.
Shutdown
Section titled “Shutdown”stop waits up to shutdownTimeout for active work. A timeout emits job:error.
dispose interrupts native Workers and waits for their finalizers. Promise Workers
must settle before disposal completes. Uninterruptible work can delay shutdown.
Cancellation cannot undo MongoDB writes or external effects.