; Queue workers for Kapitano Logistic, one group per named queue (see App\Support\Queues).
;
; Why they are separate: everything used to share one queue on one worker, so a store's slow server delayed the dashboard update queued behind its
; webhook, and an IP lookup or an image move could hold up a captain's route. Each kind of work now waits in its own line.
;
; Copy to /etc/supervisor/conf.d/kapitano-queues.conf, set the paths, then:  supervisorctl reread && supervisorctl update
;
; Requirements:
;   QUEUE_CONNECTION=redis            (the `jobs` table is polled continuously; Redis is already required)
;   REDIS_QUEUE_RETRY_AFTER=90        (must stay ABOVE every --timeout below, or a slow job is handed to a second worker while the first is still on it)
;   --tries=1 on every group          (webhooks and pushes schedule their own retries; the queue retrying as well would send twice)
;   `php artisan queue:restart` after every deploy, so workers pick up the new code.
;
; Sizing is a starting point. Watch the age of the OLDEST job per queue (`php artisan queue:monitor`), not how many there are.

; What a person is watching happen: dashboard repaints, route recalculation, offer expiry. Never put anything slow here.
[program:kapitano-queue-realtime]
command=php /var/www/kapitano_logistic/artisan queue:work redis --queue=realtime --sleep=1 --tries=1 --timeout=20
process_name=%(program_name)s_%(process_num)02d
numprocs=2
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
stopwaitsecs=30
user=www-data
redirect_stderr=true
stdout_logfile=/var/log/supervisor/kapitano-queue-realtime.log

; Everything that calls Firebase or a message gateway: pushes to captains, alerts to the office, sign-in codes. External calls, a few hundred
; milliseconds to a few seconds each.
[program:kapitano-queue-push]
command=php /var/www/kapitano_logistic/artisan queue:work redis --queue=push,default --sleep=1 --tries=1 --timeout=60
process_name=%(program_name)s_%(process_num)02d
numprocs=2
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
stopwaitsecs=70
user=www-data
redirect_stderr=true
stdout_logfile=/var/log/supervisor/kapitano-queue-push.log

; Updates to stores' servers: as slow as the slowest store, so they get their own workers and cannot hold anything else up.
[program:kapitano-queue-webhooks]
command=php /var/www/kapitano_logistic/artisan queue:work redis --queue=webhooks --sleep=1 --tries=1 --timeout=30
process_name=%(program_name)s_%(process_num)02d
numprocs=2
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
stopwaitsecs=40
user=www-data
redirect_stderr=true
stdout_logfile=/var/log/supervisor/kapitano-queue-webhooks.log

; Image conversions and the move to cloud storage: heavy, and nobody is waiting on them.
[program:kapitano-queue-media]
command=php /var/www/kapitano_logistic/artisan queue:work redis --queue=media --sleep=3 --tries=1 --timeout=80
process_name=%(program_name)s_%(process_num)02d
numprocs=1
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
stopwaitsecs=90
user=www-data
redirect_stderr=true
stdout_logfile=/var/log/supervisor/kapitano-queue-media.log
