scheduler:run
Starts the scheduler worker to execute scheduled tasks.Aliases
scheduler:workschedule:workschedule:run
Options
Restart the scheduler automatically when files change. Useful during development
Specify which tag to run. Only schedules with this tag will be executed
Examples
Start scheduler with default settings- Watch for file changes in your project
- Automatically restart the scheduler when
.tsor.jsfiles change - Ignore
node_modules,.git, andbuilddirectories - Add a 300ms debounce to prevent multiple restarts
Behavior
When you run this command:- The application is started with the scheduler provider
- A Worker instance is created
- All schedules matching the specified tag are loaded
- The
onStartingcallback is executed (if registered) - Tasks are scheduled according to their cron expressions
- The
onStartedcallback is executed (if registered) - The worker runs indefinitely until stopped
Production Usage
In production, you’ll typically run the scheduler as a background process: Using PM2/etc/systemd/system/scheduler.service:
scheduler:list
Display all registered scheduled tasks with their cron expressions and next execution times.Options
Filter schedules by tag. Only schedules with this tag will be displayed
Examples
List all schedulesOutput Format
The command displays schedules in a formatted table with three columns:- Cron Expression (yellow): The cron expression defining when the task runs
- Command (default color): The command name or closure reference
- For commands:
node ace <command>with arguments in cyan - For callbacks:
Closure #<index>
- For commands:
- Next Due (dim): When the task will run next
- Shows relative time (e.g., “in 5 minutes”, “in 2 hours”)
- Shows “Disabled” for skipped schedules
Understanding the Output
Cron Expression Format The package uses 6-field cron expressions:0 * * * * *- Every minute at :00 seconds0 0 * * * *- Every hour at :000 0 0 * * *- Every day at midnight0 30 9 * * 1-5- Weekdays at 9:30 AM
- Current time
- Schedule’s cron expression
- Configured timezone (if any)
- Enabled/disabled status
Use Cases
Verify schedules are registered- The cron expression is correct
- The schedule is enabled (not showing “Disabled”)
- The next execution time is as expected
Running Multiple Workers
You can run multiple scheduler workers with different tags simultaneously: Terminal 1 - Email queueGraceful Shutdown
The scheduler:run command handles graceful shutdown automatically:- SIGTERM: Stops all running tasks before exiting
- SIGINT (Ctrl+C): Stops all running tasks before exiting
- New task executions are prevented
- Currently running tasks are allowed to complete
- The worker stops all cron schedules
- The process exits cleanly