Queue totalSize() and JobInterrupted Event in Laravel 13.31
Laravel 13.31 delivers Queue::totalSize() for aggregate multi-queue metrics and a dedicated JobInterrupted event for handling graceful worker terminations and container preemption.
Queue Improvements in Laravel 13.31
The release of Laravel 13.31 provides two significant enhancements for background queue management: aggregate queue size introspection and graceful worker interruption events.
Aggregate Queue Sizing with Queue::totalSize()
Previously, monitoring aggregate queue depth required querying each queue name individually. Laravel 13.31 introduces Queue::totalSize():
use Illuminate\Support\Facades\Queue;
// Fetch total count across all queues on the default connection
$pendingJobs = Queue::totalSize();
// Or check specific connection
$redisDepth = Queue::connection('redis')->totalSize(['high', 'default', 'low']);
Handling Worker Terminations with JobInterrupted
When running queue workers on Kubernetes or AWS ECS, spot instance terminations send SIGTERM signals to running containers. The new JobInterrupted event allows executing cleanup logic before workers terminate:
use Illuminate\Queue\Events\JobInterrupted;
use Illuminate\Support\Facades\Event;
Event::listen(JobInterrupted::class, function (JobInterrupted $event) {
logger()->warning("Job {$event->job->resolveName()} was interrupted by system signal.");
// Release locks, update progress indicators, or send alerts
});