; ============================================
; Supervisor Configuration for WhatsApp Queue
; ============================================
; 
; Place this file in: /etc/supervisor/conf.d/whatsapp-queue.conf
; Then run:
;   sudo supervisorctl reread
;   sudo supervisorctl update
;   sudo supervisorctl start whatsapp-queue:*
;
; ============================================

[program:whatsapp-queue]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/html/artisan queue:work --queue=whatsapp --sleep=3 --tries=3 --timeout=60 --max-time=3600
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
user=www-data
numprocs=2
redirect_stderr=true
stdout_logfile=/var/log/supervisor/whatsapp-queue.log
stdout_logfile_maxbytes=10MB
stdout_logfile_backups=5
stopwaitsecs=3600

; ============================================
; Alternative: Single Process (for testing)
; ============================================
; [program:whatsapp-queue]
; command=php /var/www/html/artisan queue:work --queue=whatsapp --sleep=3 --tries=3 --timeout=60
; autostart=true
; autorestart=true
; user=www-data
; redirect_stderr=true
; stdout_logfile=/var/log/supervisor/whatsapp-queue.log

; ============================================
; Troubleshooting Commands
; ============================================
; 
; Check status:
;   sudo supervisorctl status whatsapp-queue:*
;
; View logs:
;   sudo tail -f /var/log/supervisor/whatsapp-queue.log
;
; Restart:
;   sudo supervisorctl restart whatsapp-queue:*
;
; Stop:
;   sudo supervisorctl stop whatsapp-queue:*
;
; Reload config:
;   sudo supervisorctl reread
;   sudo supervisorctl update
;
; ============================================
; Common Issues & Solutions
; ============================================
;
; 1. "spawn error" - Check:
;    - Path to artisan: php /var/www/html/artisan (adjust if different)
;    - User permissions: user=www-data (or your web server user)
;    - Log directory exists: mkdir -p /var/log/supervisor
;
; 2. "Permission denied" - Fix:
;    sudo chown -R www-data:www-data /var/www/html
;    sudo chmod -R 755 /var/www/html
;
; 3. "Command not found" - Check:
;    - PHP path: which php
;    - Artisan path: ls -la /var/www/html/artisan
;
; 4. "No such file or directory" - Fix:
;    - Create log directory: sudo mkdir -p /var/log/supervisor
;    - Set permissions: sudo chmod 755 /var/log/supervisor
;
; ============================================
