[program:aidepos-queue-worker]
; ============================================================================
; AIDEPOS QUEUE WORKER - OPTIMIZED CONFIGURATION
; ============================================================================
; This supervisor configuration runs Laravel queue workers with proper
; timeout settings to handle long-running sync jobs (up to 3 hours).
;
; INSTALLATION:
; 1. Copy this file to: /etc/supervisor/conf.d/aidepos-queue-worker.conf
; 2. Update paths below to match your server
; 3. Run: sudo supervisorctl reread
; 4. Run: sudo supervisorctl update
; 5. Run: sudo supervisorctl start aidepos-queue-worker:*
; ============================================================================

; Command to run (UPDATE PATHS!)
command=/usr/local/bin/php /home/aideeicq/public_html/artisan queue:work database --timeout=300 --tries=2 --sleep=3 --max-jobs=100 --max-time=3600

; Process configuration
process_name=%(program_name)s_%(process_num)02d
numprocs=2
; Run 2 workers in parallel for better performance
; Increase to 4-6 if you have high sync volume

; User and directory
user=aideeicq
; UPDATE: Change to your web server user (www-data, nginx, aideeicq, etc.)

directory=/home/aideeicq/public_html
; UPDATE: Change to your Laravel application directory

; Auto-start configuration
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true

; Priority and timeout
priority=999
startsecs=10
stopwaitsecs=320
; 320 seconds = per-job timeout (300s) + 20s buffer
; Must be greater than the queue:work --timeout=300 above

; Logging
stdout_logfile=/home/aideeicq/public_html/storage/logs/queue-worker.log
stdout_logfile_maxbytes=50MB
stdout_logfile_backups=5
stderr_logfile=/home/aideeicq/public_html/storage/logs/queue-worker-error.log
stderr_logfile_maxbytes=50MB
stderr_logfile_backups=5

; Environment variables
environment=
    PATH="/usr/local/bin:/usr/bin:/bin",
    HOME="/home/aideeicq",
    USER="aideeicq"

; ============================================================================
; COMMAND EXPLANATION:
; ============================================================================
;
; queue:work database
;   - Use the 'database' queue driver (matches config/queue.php)
;
; --timeout=300
;   - Per-(store, day) jobs complete in seconds to minutes
;   - The orchestrator (SyncAideposData) only fans out child jobs and finishes fast
;   - If a single job exceeds 300s, investigate — it's not normal under this design
;
; --tries=2
;   - Retry failed jobs once
;   - Gives jobs a second chance if they fail
;
; --sleep=3
;   - Sleep 3 seconds when no jobs are available
;   - Reduces CPU usage during idle periods
;
; --max-jobs=100
;   - Restart worker after processing 100 jobs
;   - Prevents memory leaks from accumulating
;
; --max-time=3600
;   - Restart worker after 1 hour of running
;   - Ensures workers don't run indefinitely
;   - Fresh workers prevent memory issues
;
; ============================================================================
; PERFORMANCE TUNING:
; ============================================================================
;
; For LOW volume (< 10 syncs per day):
;   numprocs=1    (1 worker)
;   --max-jobs=50
;
; For MEDIUM volume (10-50 syncs per day):
;   numprocs=2    (2 workers) ← CURRENT SETTING
;   --max-jobs=100
;
; For HIGH volume (50+ syncs per day):
;   numprocs=4-6  (4-6 workers)
;   --max-jobs=200
;
; ============================================================================
