;
; Supervisor configuration for Pathshalaa Queue Workers
; Location: /etc/supervisor/conf.d/pathshalaa-worker.conf
;

[program:pathshalaa-worker]
; The command to run
command=php /home/user/pathshalaa_api/artisan queue:work database --sleep=3 --tries=3 --max-time=3600 --timeout=300

; Process name (with process number)
process_name=%(program_name)s_%(process_num)02d

; Number of worker processes to run
numprocs=2

; Directory to run command from
directory=/home/user/pathshalaa_api

; Start workers automatically on supervisor start
autostart=true

; Restart workers automatically if they crash
autorestart=true

; Stop workers as a group (allows graceful shutdown)
stopasgroup=true
killasgroup=true

; User to run workers as (change to your web server user)
user=www-data

; How long to wait for shutdown before force killing (1 hour)
stopwaitsecs=3600

; Priority (lower number = higher priority)
priority=999

; Log files
stdout_logfile=/home/user/pathshalaa_api/storage/logs/worker.log
stdout_logfile_maxbytes=10MB
stdout_logfile_backups=5
redirect_stderr=true

; Environment variables
environment=
    LANG="en_US.UTF-8",
    LC_ALL="en_US.UTF-8",
    LC_LANG="en_US.UTF-8"

;
; Installation Instructions:
;
; 1. Install Supervisor:
;    sudo apt-get update
;    sudo apt-get install supervisor
;
; 2. Copy this file:
;    sudo cp /home/user/pathshalaa_api/supervisor/pathshalaa-worker.conf /etc/supervisor/conf.d/
;
; 3. Update configuration:
;    - Change 'user' to your web server user (www-data, nginx, apache, etc.)
;    - Update paths if your project is not in /home/user/pathshalaa_api
;    - Adjust 'numprocs' based on your server capacity (2-8 recommended)
;
; 4. Create log directory:
;    sudo mkdir -p /home/user/pathshalaa_api/storage/logs
;    sudo chown -R www-data:www-data /home/user/pathshalaa_api/storage/logs
;
; 5. Reload Supervisor:
;    sudo supervisorctl reread
;    sudo supervisorctl update
;
; 6. Start workers:
;    sudo supervisorctl start pathshalaa-worker:*
;
; 7. Check status:
;    sudo supervisorctl status pathshalaa-worker:*
;
; Management Commands:
;
; View logs:
;    sudo supervisorctl tail -f pathshalaa-worker:pathshalaa-worker_00 stdout
;
; Restart workers:
;    sudo supervisorctl restart pathshalaa-worker:*
;
; Stop workers:
;    sudo supervisorctl stop pathshalaa-worker:*
;
; Restart all:
;    sudo supervisorctl restart all
;
; Configuration Options Explained:
;
; --sleep=3           Wait 3 seconds between job checks (reduces CPU usage)
; --tries=3           Retry failed jobs 3 times
; --max-time=3600     Restart worker every hour (prevents memory leaks)
; --timeout=300       Kill job if it runs longer than 5 minutes
; numprocs=2          Run 2 worker processes (adjust based on load)
;
