Skip to content

Queues & background jobs

Background work in Inventorix — including asset imports and exports, warranty-expiry digest emails, and applying runtime settings to long-lived workers — runs on queues. Laravel Horizon manages the queue workers and provides a real-time dashboard.

Inventorix uses Redis as the queue backend for Horizon. The default queue connection is set by the QUEUE_CONNECTION environment variable.

VariableDefaultPurpose
QUEUE_CONNECTIONdatabaseSet to redis to use Horizon
REDIS_HOST127.0.0.1Redis server host
REDIS_PORT6379Redis server port
REDIS_PASSWORD(null)Redis password (leave null if not set)
REDIS_CLIENTphpredisPHP Redis client (phpredis or predis)

Horizon is the worker process that picks up queued jobs. It is not started automatically by the Docker entrypoint — you must run it as a separate process or container.

Terminal window
php artisan horizon

In a Docker Compose setup, define a dedicated worker service:

worker:
image: your-inventorix-image
command: php artisan horizon
depends_on:
- redis
environment:
QUEUE_CONNECTION: redis
REDIS_HOST: redis

To stop Horizon gracefully (allowing in-flight jobs to complete before exiting):

Terminal window
php artisan horizon:terminate

The dashboard is available at /horizon (e.g. https://your-domain.com/horizon). It shows queued, processing, completed, and failed jobs, along with throughput metrics.

Horizon’s worker configuration is defined in config/horizon.php. The default supervisor processes the default queue:

SettingValuePurpose
ConnectionredisQueue connection
QueuedefaultQueue name
BalanceautoAuto-scales workers
Auto-scaling strategytimeScales based on queue wait time
Max processes (production)10Maximum concurrent workers
Max processes (local)3Maximum concurrent workers in development
Memory limit per worker128 MBWorker restart threshold
Job timeout60 sPer-job execution time limit
Job retries1How many times a job is attempted before failing

The master supervisor has a separate memory limit of 64 MB. If exceeded, Horizon restarts automatically.

CategoryRetention
Recent / pending / completed jobs60 minutes
Failed jobs7 days (10 080 minutes)

Jobs not processing

  1. Verify Horizon is running: php artisan horizon:status
  2. Check that QUEUE_CONNECTION=redis in the environment where Horizon runs.
  3. Confirm Redis is reachable: redis-cli -h $REDIS_HOST ping

Jobs stuck in pending

If a job has been pending longer than the retry_after threshold (default 90 seconds for the Redis connection), Horizon will re-queue it. If jobs permanently pile up, check worker logs (storage/logs/laravel.log) for exceptions.

Retrying failed jobs

Terminal window
# List failed jobs
php artisan queue:failed
# Retry a single failed job by ID
php artisan queue:retry <id>
# Retry all failed jobs
php artisan queue:retry all

Flushing failed jobs

Terminal window
php artisan queue:flush

Horizon memory issues

If Horizon restarts frequently due to memory, increase the memory_limit value in config/horizon.php and the per-worker memory value in the supervisor definition.