Creates a scheduler plugin.
Options for distributed locking.
-
client: IRedisLockClient
Injected ioredis-compatible client (preferred over lazy load).
-
enabled: boolean
Enable distributed locking. Default
false. -
lock: IDistributedLock
Custom lock implementation. Takes priority over
storagewhen present. -
storage: "redis"
Lock backend. Only
'redis'is supported whenenabled: true. -
ttlMs: number
Lock TTL in milliseconds. Must exceed the job's worst-case runtime.
-
url: string
Redis connection URL. Default
'redis://localhost:6379'.
Distributed lock interface.
-
acquire(): Promise<string | null>key: string,ttlMs: number
Attempt to acquire the lock.
-
release(): Promise<void>key: string,token: string
Release a previously acquired lock.
Minimal ioredis client shape required by RedisLock.
-
eval(): Promise<number | string | null>script: string,numkeys: number,...keysAndArgs: string[]
EVAL script numkeys keys... argv...
-
quit(): Promise<void>
Quit the connection
-
set(): Promise<string | null>key: string,value: string,option: string,px: "PX",ttl: number
SET key value [NX] [PX ttl] - PX is the milliseconds flag
In-process job scheduler.
-
cron<T = unknown>(): Promise<void>name: string,expression: string,handler: SchedulerJobHandler<T>,options?: ScheduleOptions<T>
Schedule a recurring job using a 5-field cron expression (UTC).
-
delay<T = unknown>(): Promise<void>name: string,delayMs: number,handler: SchedulerJobHandler<T>,options?: ScheduleOptions<T>
Schedule a one-shot delayed job.
-
every<T = unknown>(): Promise<void>name: string,intervalMs: number,handler: SchedulerJobHandler<T>,options?: ScheduleOptions<T>
Schedule a recurring job that fires every
intervalMsmilliseconds. -
getNextRun(name: string): Promise<number>
Return the next scheduled fire time as epoch milliseconds.
-
pause(name: string): Promise<void>
Pause a scheduled job without dropping its configuration.
-
remove(name: string): Promise<void>
Remove a scheduled job entirely.
-
resume(name: string): Promise<void>
Resume a paused job.
Retry configuration for a scheduled job.
-
backoff: SchedulerBackoff
Backoff strategy. Defaults to
'fixed'. -
delay: number
Base delay in milliseconds for the first retry.
-
limit: number
Maximum number of attempts before giving up (1-based minimum).
A scheduled job instance handed to the handler.
-
attempts: number
Current attempt number (1-based).
-
data: T
Payload data supplied by the caller.
-
id: string
Unique job identifier.
-
name: string
Human-readable job name.
Options passed when scheduling a job.
-
data: T
Payload data handed to the handler.
-
retry: RetryOptions
Retry configuration. When absent the job runs once.
Plugin options passed to SchedulerPlugin().
-
behaviors: readonly (IIngressBehavior | RegistryFactory<IIngressBehavior>)[]
Ingress behaviours wrapped around every job handler — the scheduler arm of the transport-neutral behaviour chain shared with the websocket, queue, and messaging plugins (
IIngressBehaviorin@setu-ts/common). -
distributedLock: DistributedLockOptions
Distributed lock configuration.
-
jobs: readonly SchedulerJobEntry[]
Jobs registered declaratively, as an alternative to calling
scheduler.cron()/every()/delay()imperatively afterstart(). Each entry — instance orRegistryFactory— produces one registration call, dispatched on itstrigger, so a job can be declared where the plugin is composed instead of after the application has started. -
timezone: string
Timezone for cron evaluation. Only
'UTC'is supported in this release.
Backoff strategy for retry delays.
| { readonly trigger: "every"; readonly name: string; readonly intervalMs: number; readonly handler: SchedulerJobHandler; readonly data?: unknown; readonly retry?: RetryOptions; }
| { readonly trigger: "delay"; readonly name: string; readonly delayMs: number; readonly handler: SchedulerJobHandler; readonly data?: unknown; readonly retry?: RetryOptions; }
The declarative form of one scheduler job registration — the entry an
application writes instead of calling cron()/every()/delay()
imperatively after start().
| RegistryFactory<SchedulerJobDefinition>
One entry of SchedulerPluginOptions.jobs: a job definition, or
a RegistryFactory producing one when the definition needs a
resolved capability.
Handler invoked when a scheduled job fires.
Usage
import * as Job_scheduling_plugin__cron__delayed__recurring_jobs_with_distributed_locking__ from "scheduler-plugin/src/index.ts";