[supervisord]
nodaemon=true
user=root
logfile=/var/log/supervisor/supervisord.log
pidfile=/var/run/supervisord.pid
loglevel=info

; ==============================================================================
; Nginx — Serves HTTP requests
; ==============================================================================
[program:nginx]
command=nginx -g "daemon off;"
autostart=true
autorestart=true
startretries=5
stderr_logfile=/var/log/supervisor/nginx.err.log
stdout_logfile=/var/log/supervisor/nginx.out.log
priority=10

; ==============================================================================
; PHP-FPM — Processes PHP requests from Nginx
; ==============================================================================
[program:php-fpm]
command=php-fpm -F
autostart=true
autorestart=true
startretries=5
stderr_logfile=/var/log/supervisor/php-fpm.err.log
stdout_logfile=/var/log/supervisor/php-fpm.out.log
priority=20

; ==============================================================================
; Queue Worker — HIGH priority queue (payments)
; ==============================================================================
; Runs with --max-jobs=500 to prevent memory leaks in long-running workers.
; After 500 jobs, the worker exits and supervisor restarts it cleanly.
; This is intentional and correct — not a crash.
;
; --sleep=1: Poll for new jobs every 1 second (low latency for payments)
; --timeout=60: Kill jobs that run over 60 seconds (prevents zombie jobs)
; --tries=0: Don't retry here — each job class defines its own retry count
[program:queue-payments]
command=php /var/www/html/artisan queue:work redis
    --queue=payments
    --sleep=1
    --tries=0
    --timeout=60
    --max-jobs=500
    --max-time=3600
    --no-interaction
user=www-data
autostart=true
autorestart=true
startretries=10
startsecs=1
stopwaitsecs=90
stderr_logfile=/var/log/supervisor/worker-payments.err.log
stdout_logfile=/var/log/supervisor/worker-payments.out.log
priority=30
numprocs=2
process_name=%(program_name)s_%(process_num)02d

; ==============================================================================
; Queue Worker — DEFAULT queue (orders, emails, general)
; ==============================================================================
[program:queue-default]
command=php /var/www/html/artisan queue:work redis
    --queue=default,emails,notifications
    --sleep=3
    --tries=0
    --timeout=90
    --max-jobs=500
    --max-time=3600
    --no-interaction
user=www-data
autostart=true
autorestart=true
startretries=10
startsecs=1
stopwaitsecs=120
stderr_logfile=/var/log/supervisor/worker-default.err.log
stdout_logfile=/var/log/supervisor/worker-default.out.log
priority=40
numprocs=2
process_name=%(program_name)s_%(process_num)02d

; ==============================================================================
; Scheduler — Runs every minute via `schedule:work`
; ==============================================================================
; `schedule:work` is a long-running command that loops every 60 seconds.
; This is the correct way to run the scheduler in Docker (no cron required).
; On a VPS with cron: remove this and add `* * * * * php artisan schedule:run`
[program:scheduler]
command=php /var/www/html/artisan schedule:work
user=www-data
autostart=true
autorestart=true
startretries=5
stderr_logfile=/var/log/supervisor/scheduler.err.log
stdout_logfile=/var/log/supervisor/scheduler.out.log
priority=50
