跳到主要内容

⏰ 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

TaskFrequencyDescription
dispatch-monitor-checksEvery 10 secondsDispatches check jobs for monitors that need checking
check-stale-heartbeatsEvery minuteMarks missed heartbeats as Down
check-stale-agentsEvery 5 minutesMarks non-reporting agents as Down
ai-predictive-checkEvery 30 minutesRuns AI outage prediction
ai-weekly-reportMonday 8:00 AMGenerates AI weekly reports
purge-old-dataDaily 3:00 AMDeletes 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

QueuePurpose
checks-criticalMonitors with ≤60s intervals
checks-standardMonitors with >60s intervals
defaultNotifications 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

MonitorsRecommended Workers
< 502 workers
50 - 2004 workers
200 - 5006-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.