[program:school-erp-queue-worker]
;--------------------------------------------------------------------------
; Laravel Queue Worker — Supervisor Configuration
;--------------------------------------------------------------------------
;
; INSTALLATION (aaPanel VPS):
;
;   1. Install Supervisor:
;      sudo apt install supervisor
;
;   2. Copy this file to Supervisor config directory:
;      sudo cp /www/wwwroot/project/supervisor.conf /etc/supervisor/conf.d/school-erp-worker.conf
;
;   3. Update paths below to match your server setup
;
;   4. Reload Supervisor:
;      sudo supervisorctl reread
;      sudo supervisorctl update
;      sudo supervisorctl start school-erp-queue-worker:*
;
;   5. Set in your .env:
;      QUEUE_WORKER_MODE=supervisor
;
;   6. Verify it's running:
;      sudo supervisorctl status
;
; HOW IT WORKS:
;   Supervisor keeps the queue:work process running permanently.
;   Unlike the scheduler approach (which boots a new PHP process every minute),
;   this boots PHP ONCE and keeps it alive. Massive CPU/RAM savings.
;
;   If the worker crashes, Supervisor restarts it automatically.
;   If you deploy new code, restart the worker to pick up changes:
;      sudo supervisorctl restart school-erp-queue-worker:*
;
; FLAGS EXPLAINED:
;   --sleep=3       Polls for new jobs every 3 seconds (not continuous spin)
;   --tries=3       Retry failed jobs 3 times before moving to failed_jobs table
;   --max-time=3600 Worker auto-restarts every hour (prevents memory leaks)
;   --memory=256    Kill worker if RAM exceeds 256MB (prevents runaway jobs)
;   --timeout=120   Kill individual jobs that run longer than 2 minutes
;                   (except GenerateBulkMarksheetJob which has its own $timeout=900)
;
;--------------------------------------------------------------------------

; UPDATE THESE PATHS to match your server:
command=php /www/wwwroot/your-project-path/artisan queue:work database --sleep=3 --tries=3 --max-time=3600 --memory=256 --timeout=120
directory=/www/wwwroot/your-project-path

; Process management
process_name=%(program_name)s_%(process_num)02d
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true

; Run 2 worker processes for parallel job processing.
; Increase to 3-4 on servers with 4+ CPU cores and 4GB+ RAM.
; On 1-2GB RAM servers, keep this at 1.
numprocs=2

; Run as the web server user (aaPanel default: www)
user=www

; Logging
redirect_stderr=true
stdout_logfile=/www/wwwroot/your-project-path/storage/logs/queue-worker.log
stdout_logfile_maxbytes=10MB
stdout_logfile_backups=3

; Restart throttling — don't hammer if there's a persistent error
startsecs=5
startretries=3
