scheduler:run or scheduler:work commands.
Basic usage
To start the scheduler and begin executing your scheduled tasks, run:scheduler:work command is an alias that works identically:
- Boot the scheduler and load all defined schedules
- Start executing tasks based on their cron expressions
- Keep the process alive to continue running scheduled tasks
Development mode with auto-restart
During development, you can use the--watch flag to automatically restart the scheduler when files are modified:
.ts and .js files, excluding:
node_modules/.git/build/
The
--watch flag spawns a child process running scheduler:run, making it easy to develop and test your scheduled tasks.Filtering by tags
You can filter which scheduled tasks to run using the--tag flag:
--tag=reports will only execute the daily report task.
Difference between run and work
There is no functional difference betweenscheduler:run and scheduler:work. Both commands:
- Accept the same flags (
--watch,--tag) - Execute scheduled tasks in the same way
- Keep the process alive
scheduler:work command exists as an alias for convenience and familiarity with other task queue systems.
Running in production
In production, you typically want to run the scheduler as a long-running process managed by a process manager:Using PM2
Using systemd
Create a systemd service file:With Docker
Multiple scheduler instances
You can run multiple scheduler instances with different tags to distribute workloads:- Scale specific workloads independently
- Isolate critical tasks from resource-intensive ones
- Deploy scheduler instances on different servers