Documentation / zerotal / scheduler / Schedule
Abstract Class: Schedule
Defined in: packages/scheduler/src/Schedule.ts:30
Base class for convention-based scheduled tasks. Drop a subclass in app/schedules/ and it is
auto-registered at boot (worker + console environments) by the scheduler's convention loader.
Define the cadence with either cron or the fluent frequency() method, put the work in
handle(), and tune behaviour with the declarative settings below.
Examples
import { Schedule } from "@zerotal/scheduler";
export class SendDailyReports extends Schedule {
cron = "0 8 * * *"; // every day at 08:00
timezone = "Africa/Johannesburg";
withoutOverlapping = true;
async handle(): Promise<void> {
await Queue.dispatch(new SendReportsJob());
}
}
// fluent cadence instead of a raw cron string
export class PruneTempFiles extends Schedule {
frequency(every) { return every.dailyAt("02:30"); }
async handle() { ... }
}
Constructors
Constructor
new Schedule():
Schedule
Returns
Schedule
Properties
cron?
optionalcron?:string
Defined in: packages/scheduler/src/Schedule.ts:38
Cron expression (5- or 6-field). Set this OR override frequency.
Examples: "* * * * *" (every minute), "0 8 * * 1" (Mondays at 08:00).
name?
optionalname?:string
Defined in: packages/scheduler/src/Schedule.ts:49
Task name shown in schedule:list and logs. Defaults to the class name.
timezone?
optionaltimezone?:string
Defined in: packages/scheduler/src/Schedule.ts:52
IANA timezone the cron expression is evaluated in (default: system timezone).
withoutOverlapping?
optionalwithoutOverlapping?:boolean|OverlapLockOptions
Defined in: packages/scheduler/src/Schedule.ts:59
Prevent overlapping runs. true skips a tick while a previous run is still active and,
when a lock driver is configured, also takes a cross-process lock. Pass
{ crossProcess: false } to guard within this process only.
environments?
optionalenvironments?:string[]
Defined in: packages/scheduler/src/Schedule.ts:62
Only run when APP_ENV is one of these values.
inBackground?
optionalinBackground?:boolean
Defined in: packages/scheduler/src/Schedule.ts:65
Run the body without blocking the scheduler tick (fire-and-forget).
between?
optionalbetween?: [string,string]
Defined in: packages/scheduler/src/Schedule.ts:68
Only run between ["HH:MM", "HH:MM"].
unlessBetween?
optionalunlessBetween?: [string,string]
Defined in: packages/scheduler/src/Schedule.ts:71
Never run between ["HH:MM", "HH:MM"].
pingBefore?
optionalpingBefore?:string
Defined in: packages/scheduler/src/Schedule.ts:74
Health-check pings (e.g. healthchecks.io). URLs are fetched at each lifecycle point.
pingAfter?
optionalpingAfter?:string
Defined in: packages/scheduler/src/Schedule.ts:75
pingOnSuccess?
optionalpingOnSuccess?:string
Defined in: packages/scheduler/src/Schedule.ts:76
pingOnFailure?
optionalpingOnFailure?:string
Defined in: packages/scheduler/src/Schedule.ts:77
appendOutputTo?
optionalappendOutputTo?:string
Defined in: packages/scheduler/src/Schedule.ts:80
Append captured console output to a file.
emailOutputTo?
optionalemailOutputTo?:string
Defined in: packages/scheduler/src/Schedule.ts:83
Email captured console output (requires an output mailer to be configured).
Methods
handle()
abstracthandle():void|Promise<void>
Defined in: packages/scheduler/src/Schedule.ts:32
The work performed on each run. Required.
Returns
void | Promise<void>
frequency()?
optionalfrequency(every):ScheduledTask
Defined in: packages/scheduler/src/Schedule.ts:46
Build the cadence fluently using the scheduler's frequency helpers, instead of a raw cron string. Return the configured task.
Parameters
every
Returns
Example
frequency(every) { return every.everyFiveMinutes(); }
when()?
optionalwhen():boolean|Promise<boolean>
Defined in: packages/scheduler/src/Schedule.ts:86
Dynamic guard — the task runs only when this resolves truthy.
Returns
boolean | Promise<boolean>
skip()?
optionalskip():boolean|Promise<boolean>
Defined in: packages/scheduler/src/Schedule.ts:89
Dynamic guard — the task is skipped when this resolves truthy.
Returns
boolean | Promise<boolean>