ScheduleModule runs cron jobs and interval tasks inside nestrs. Declare scheduled work with #[cron] and #[interval] macros on a #[schedule_routes] impl block.
ScheduleModule brings recurring background tasks into your nestrs application without relying on the OS cron daemon or an external scheduler. It is backed by tokio-cron-scheduler and starts automatically when your app calls listen. Declare task handlers with #[cron("...")] or #[interval(ms)] on a #[schedule_routes] impl block, register the service as a provider, and import ScheduleModule::for_root().
ScheduleModule is designed for app-local tasks — work that belongs in the same process as your HTTP server. It is not a distributed scheduler. For durable, multi-instance job queues, see QueuesModule.
Import ScheduleModule::for_root() and add your task provider to providers. The ScheduleRuntime is automatically exported by the module and manages the underlying scheduler lifecycle.
use nestrs::prelude::*;#[module( imports = [ScheduleModule::for_root()], providers = [TasksService],)]struct AppModule;
ScheduleRuntime is the provider that owns the tokio_cron_scheduler::JobScheduler. You can inject it if you need to inspect or extend the scheduler at runtime, but most applications only interact with it indirectly through ScheduleModule::for_root().
ScheduleModule and HTTP controllers live in the same module graph. Scheduled tasks can share providers — inject a CacheService or PrismaService into your TasksService the same way you would in a controller.
Confirm ScheduleModule::for_root() is in imports and TasksService is in providers. The scheduler only starts when listen is called.
”feature not enabled”
Add schedule to features in Cargo.toml.
Cron expression parse error
Use the six-field format (seconds as the first field). Five-field standard cron expressions are not supported.
Tasks stop after first error
Panics inside a scheduled task can bring down the tokio task. Wrap task bodies in catch_unwind or use Result-returning tasks and log errors explicitly.