⏰ Scheduler & Queue Workers
The scheduler and queue workers are the backbone of Monitron — they make monitoring actually happen.
⏰ The Scheduler
The Laravel scheduler runs every minute via cron and dispatches various tasks:
Scheduled Tasks
| Task | Frequency | Description |
|---|---|---|
dispatch-monitor-checks | Every 10 seconds | Dispatches check jobs for monitors that need checking |
check-stale-heartbeats | Every minute | Marks missed heartbeats as Down |
check-stale-agents | Every 5 minutes | Marks non-reporting agents as Down |
ai-predictive-check | Every 30 minutes | Runs AI outage prediction |
ai-weekly-report | Monday 8:00 AM | Generates AI weekly reports |
purge-old-data | Daily 3:00 AM | Deletes data older than retention period |
Cron Entry
* * * * * cd /var/www/monitron && php artisan schedule:run >> /dev/null 2>&1
Verify It's Running
php artisan schedule:list
🔄 Queue Workers
Queue workers process monitoring checks and notification deliveries asynchronously.
Queue Names
| Queue | Purpose |
|---|---|
checks-critical | Monitors with ≤60s intervals |
checks-standard | Monitors with >60s intervals |
default | Notifications and other jobs |
Supervisor Configuration
[program:monitron-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/monitron/artisan queue:work --sleep=3 --tries=3 --max-time=3600
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
user=www-data
numprocs=2
redirect_stderr=true
stdout_logfile=/var/www/monitron/storage/logs/worker.log
stopwaitsecs=3600
Scaling Workers
| Monitors | Recommended Workers |
|---|---|
| < 50 | 2 workers |
| 50 - 200 | 4 workers |
| 200 - 500 | 6-8 workers |
| 500+ | 10+ workers |
Useful Commands
# Check worker status
sudo supervisorctl status
# Restart workers (after code changes)
php artisan queue:restart
# Monitor queue sizes
php artisan queue:monitor
# Process a single job (debugging)
php artisan queue:work --once
🔄 After Code Changes
Whenever you update Monitron:
php artisan queue:restart
This gracefully restarts all workers. Supervisor will automatically start new ones.