Laravel Horizon Documentation

repository·5.x·Indexed 26 days ago

https://github.com/laravel/horizon

A dashboard and configuration system for managing Redis-powered queues in Laravel applications. Horizon provides real-time monitoring of job metrics, code-driven worker configuration, and tools for managing supervisor environments, auto-scaling, and job tagging. It includes features for routing LongWaitDetected notifications via Email, Slack, and SMS, as well as utilities for managing job payloads and snapshot retention.

Tokens
2.4K
Snippets
1
Records
27
Agent score
88%

What's inside Laravel Horizon

  1. Introduction to Laravel Horizon

    5.x
    Laravel Horizon provides a dashboard and code-driven configuration for Laravel-powered Redis queues. It allows you to monitor key metrics such as job throughput, runtime, and job failures. Worker configurations are managed in a single configuration file, enabling version control and team collaboration.
  2. Route Horizon notifications in HorizonServiceProvider

    5.x

    You can configure where Horizon sends LongWaitDetected alerts by using the built-in routing methods within the boot() method of your App\Providers\HorizonServiceProvider. Horizon automatically wires the LongWaitDetected event to these routes.

    Available routing methods:

    • Horizon::routeMailNotificationsTo(...)
    • Horizon::routeSlackNotificationsTo(...)
    • Horizon::routeSmsNotificationsTo(...)
  3. Configure Horizon supervisor environments

    5.x

    Horizon uses a hierarchical configuration structure for supervisors. The defaults array defines the base configuration for all supervisors. The environments array is used to patch these defaults for specific environments (e.g., production).

    Important: The environments array merges into defaults rather than replacing it. You only need to specify the keys you wish to override in your environment-specific blocks.

  4. Use automatic Eloquent model tagging in Horizon

    5.x
    Horizon automatically tags jobs that accept Eloquent model instances in their constructor. The tag format is ModelClass:id (e.g., App\Models\User:42). These tags are immediately available for filtering in the Horizon dashboard. You only need to implement a tags() method in your job class if you require custom tags in addition to this automatic behavior.
  5. Upgrade to Horizon 5.0 from 4.x

    5.x

    When upgrading to version 5.0, ensure your environment meets the following requirements and note the following breaking changes:

    Requirements

    • Minimum PHP Version: PHP 7.3
    • Minimum Laravel Version: Laravel 8.0

    Breaking Changes

    • Chronos Replaced By Carbon: Internal usage of Chronos has been replaced by Carbon for ecosystem consistency.
    • Deprecated Flags: The following flags are deprecated and should be replaced:
      • Replace timeoutAt with retryUntil.
      • Replace delay with backoff.
  6. Upgrade to Horizon 3.0 from 2.x

    5.x

    When upgrading to version 3.0, ensure your environment meets the following requirement:

    Requirements

    • Minimum Laravel Version: Laravel 5.7 is the minimum required version. You must upgrade to this version to continue using Horizon.
  7. Enforce queue priority using separate supervisors

    5.x

    When using balance: auto on a single supervisor, Horizon ignores the order of the queue array for load balancing purposes. To ensure specific queues are processed with higher priority, you must create separate named supervisors.

    For example, to prioritize a notifications queue over a default queue, create one supervisor for notifications with a higher maxProcesses and a second supervisor for default with a lower maxProcesses cap.

  8. Upgrade to Horizon 4.0 from 3.x

    5.x

    When upgrading to version 4.0, ensure your environment meets the following requirements and note the following breaking changes:

    Requirements

    • Minimum Laravel Version: Laravel 7.0

    Breaking Changes

    • Predis Dependency: Predis is no longer a required dependency. If you wish to continue using Predis, you must explicitly add it to your composer.json file.
    • Default Predis Prefix: The default Predis prefix now starts with the application name. To maintain the old prefix behavior, add the following to your .env file:
    HORIZON_PREFIX="horizon:"
    • Command Rename: The horizon:assets command has been renamed to horizon:publish.
  9. Configure LongWaitDetected threshold in config/horizon.php

    5.x

    To control when Horizon fires a LongWaitDetected event, adjust the waits array in your config/horizon.php file. The value defines the maximum number of seconds a job can wait in a specific queue before the event is triggered. For example, 'redis:default' => 60 means jobs in the default queue will trigger an alert if they wait longer than 60 seconds.

    Note: Adjust this configuration value to change alert frequency; do not attempt to change this via notification routing.