Usage Chart
How strongly this package shapes the runtime
Package Flow
How this package moves through xtaskjs runtime phases
Before startup
Decorate service methods with Cron, Every, Interval, or Timeout so the scheduler can discover jobs from the DI container.
During CreateApplication()
Scheduler discovery runs after the container is ready, wiring jobs into lifecycle phases and enabling boot-time execution or grouped control.
During app.close()
Recurring timers and cron handles are stopped automatically so background work does not outlive the application process.
API Surface
Representative exports from the upstream package
Scheduling decorators
- Cron
- Every
- Interval
- Timeout
Runtime control
- SchedulerService
- InjectSchedulerService
Lifecycle surface
- InjectSchedulerLifecycleManager
- initializeSchedulerIntegration
- shutdownSchedulerIntegration
Usage
Typical adoption flow
1. Decorate job methods
Choose Cron for calendar schedules, Every or Interval for repeated delays, and Timeout for one-shot post-startup work.
2. Organize jobs with options
Use names, groups, retries, timezone overrides, and runOnBoot or runOnInit to reflect operational intent in code.
3. Inspect and trigger jobs at runtime
Inject SchedulerService when operators or diagnostics endpoints need to list jobs, run one immediately, or rerun a whole group.
Example
Reference snippet
import { Service } from "@xtaskjs/core";
import { Cron, InjectSchedulerService, SchedulerService, Timeout } from "@xtaskjs/scheduler";
@Service()
export class ReportsScheduler {
constructor(
@InjectSchedulerService()
private readonly scheduler: SchedulerService
) {}
@Cron("0 */5 * * * *", { name: "reports.flush", group: "reports", runOnBoot: true })
flushReports() {
console.log("flush pending reports");
}
@Timeout("30s", { name: "reports.warmup" })
warmup() {
console.log("warm cache once after startup");
}
async rerunReports() {
await this.scheduler.runGroup("reports");
}
}
Samples
Official samples to inspect next
Reference samples: 11-scheduler_app
Related
Packages commonly used with this one