Skip to content

Cookbook

Cookbook

Short, concrete recipes for the things you'll wire up on day one. Code first, explanation second.

Alerting

The autoscaler emits a handful of events your app can listen to. These recipes hook them up to the three places most Laravel teams actually read:

All three transport recipes use the built-in AlertRateLimiter so you don't get 50 Slack pings for one breach.

Cluster Monitoring

  • Export Cluster Metrics — expose clusterMetrics() and ClusterScalingSignalUpdated to Prometheus, dashboards, or cboxdk/laravel-queue-monitor

Events the autoscaler emits

Event When Fires
SlaBreached Oldest job age ≥ SLA target Once on state entry
SlaRecovered Oldest job age drops below SLA target Once on state exit
SlaBreachPredicted Forecaster predicts pickup time will exceed SLA Per evaluation cycle during risk
WorkersScaled Workers spawn or terminate Per scaling action
ScalingDecisionMade Any scaling decision (including HOLD) Per evaluation cycle
FuseTripped Failure rate crosses the threshold, scaling held at workers.min Once on state entry
FuseProbing Cooldown elapsed, a probe tests for recovery Once per probe
FuseRecovered Probe succeeded, normal scaling resumes Once on state exit

SlaBreached/SlaRecovered and all three fuse events already fire at most once per state change, so they don't need additional rate-limiting. SlaBreachPredicted and WorkersScaled can fire rapidly during flapping — those are the events where rate-limiting matters.

The rate limiter in one line

use Cbox\LaravelQueueAutoscale\Alerting\AlertRateLimiter;

public function __construct(private AlertRateLimiter $limiter) {}

public function handle(SlaBreached $event): void
{
    if (! $this->limiter->allow("slack:{$event->connection}:{$event->queue}")) {
        return;
    }
    // send the alert
}

Default cooldown is 300 seconds (5 min), configurable via queue-autoscale.alerting.cooldown_seconds or the QUEUE_AUTOSCALE_ALERT_COOLDOWN env var.