Laravel 13.31: Queue totalSize() &amp; JobInterrupted Event | Mohamed Said        [  ![Mohamed Said](https://cdn.msaied.com/01KT78WE565VEMM3PSNQAAB0MH.png)   Mohamed Said Laravel Backend Engineer  ](https://www.msaied.com) [ Home ](https://www.msaied.com) [ Projects ](https://www.msaied.com/projects) [ Articles  ](https://www.msaied.com/articles) [ Certificates ](https://www.msaied.com/certificates) [ Contact ](https://www.msaied.com#contact-section) 

       [  ](https://github.com/EG-Mohamed)       

 [ Home ](https://www.msaied.com) [ Projects ](https://www.msaied.com/projects) [ Articles ](https://www.msaied.com/articles) [ Certificates ](https://www.msaied.com/certificates) [ Contact ](https://www.msaied.com#contact-section) 

  [ home ](https://www.msaied.com)    [ articles ](https://www.msaied.com/articles)    Queue totalSize() and JobInterrupted Event in Laravel 13.31        On this page       1. [  What's New in Laravel 13.31 ](#whats-new-in-laravel-1331)
2. [  Queue totalSize() Method ](#queue-codetotalsizecode-method)
3. [  JobInterrupted Event ](#codejobinterruptedcode-event)
4. [  Chaperone Support for BelongsToMany Pivot Models ](#chaperone-support-for-codebelongstomanycode-pivot-models)
5. [  once Assertions for Mail and Notification Fakes ](#codeoncecode-assertions-for-mail-and-notification-fakes)
6. [  Vite devServerUrl() Helper ](#vite-codedevserverurlcode-helper)
7. [  Additional Fixes and Improvements ](#additional-fixes-and-improvements)
8. [  Key Takeaways ](#key-takeaways)

  ![Queue totalSize() and JobInterrupted Event in Laravel 13.31](https://cdn.msaied.com/648/d0e925e5b65d5b1d925fdaf612af5db2.png)

 [  Laravel ](https://www.msaied.com/articles?category=laravel)  #Laravel 13   #Queue   #Eloquent   #Testing   #Release  

 Queue totalSize() and JobInterrupted Event in Laravel 13.31 
=============================================================

     9 Sep 2026      3 min read    ![Mohamed Said](https://cdn.msaied.com/01M22N44A70A5MC2S599JP0MPH.webp)  Mohamed Said  

       Table of contents

1. [  01   What's New in Laravel 13.31  ](#whats-new-in-laravel-1331)
2. [  02   Queue totalSize() Method  ](#queue-codetotalsizecode-method)
3. [  03   JobInterrupted Event  ](#codejobinterruptedcode-event)
4. [  04   Chaperone Support for BelongsToMany Pivot Models  ](#chaperone-support-for-codebelongstomanycode-pivot-models)
5. [  05   once Assertions for Mail and Notification Fakes  ](#codeoncecode-assertions-for-mail-and-notification-fakes)
6. [  06   Vite devServerUrl() Helper  ](#vite-codedevserverurlcode-helper)
7. [  07   Additional Fixes and Improvements  ](#additional-fixes-and-improvements)
8. [  08   Key Takeaways  ](#key-takeaways)

 What's New in Laravel 13.31
---------------------------

The Laravel team released **v13.31.0** on September 8, 2026, packed with quality-of-life improvements for queue management, Eloquent relationships, testing, and front-end tooling. Here is a breakdown of the highlights.

---

Queue `totalSize()` Method
--------------------------

Contributed by [Jack Bayliss](https://github.com/jackbayliss), the new `Queue::totalSize()` method gives you a single call to count every job on a queue connection — pending, delayed, and reserved — without manually summing three separate methods.

```php
// Before
$total = Queue::totalPendingSize()
       + Queue::totalDelayedSize()
       + Queue::totalReservedSize();

// After
$total = Queue::totalSize();

```

This is especially useful for dashboards and monitoring scripts that need a quick health check on queue depth.

---

`JobInterrupted` Event
----------------------

Also contributed by Jack Bayliss, the new `JobInterrupted` event fires whenever a job that implements the `Interruptible` contract is interrupted by the queue worker. You can listen for it to run cleanup logic, flush state, or write an audit log entry.

```php
use Illuminate\Queue\Events\JobInterrupted;

Event::listen(JobInterrupted::class, function (JobInterrupted $event) {
    // Perform cleanup or logging here
});

```

This closes a long-standing gap: previously there was no first-class hook for reacting to a worker-initiated interruption.

---

Chaperone Support for `BelongsToMany` Pivot Models
--------------------------------------------------

[Caleb White](https://github.com/calebdw) added chaperone support to `BelongsToMany` relationships. When you use a custom pivot model that defines `BelongsTo` relations back to the parent and related models, calling `->chaperone()` on the relationship now hydrates those relations from already-loaded model instances instead of issuing extra database queries.

```php
class Tag extends Model
{
    public function posts(): BelongsToMany
    {
        return $this->belongsToMany(Post::class)
            ->using(PostTagPivot::class)
            ->chaperone(); // auto-guesses relationship names
    }
}

```

If the relationship names are non-standard, you can override them explicitly:

```php
->chaperone(declaring: 'tag', related: 'post');

```

If no custom pivot model is provided, `->chaperone()` is a no-op, so it is safe to add without side effects.

---

`once` Assertions for Mail and Notification Fakes
-------------------------------------------------

[@talaridisTh](https://github.com/talaridisTh) added expressive `assertSentOnce` / `assertQueuedOnce` helpers that replace the verbose `*Times(..., 1)` pattern:

```php
// Before
Mail::assertSentTimes(OrderShipped::class, 1);
Notification::assertSentToTimes($user, InvoicePaid::class, 1);

// After
Mail::assertSentOnce(OrderShipped::class);
Notification::assertSentToOnce($user, InvoicePaid::class);

```

The same pattern applies to `assertQueuedOnce` and `assertSentOnDemandOnce`.

---

Vite `devServerUrl()` Helper
----------------------------

[@ramonmalcolm10](https://github.com/ramonmalcolm10) added a `devServerUrl()` method to the Vite class, making it straightforward to retrieve the running Vite development server URL programmatically — useful when generating asset URLs outside of standard Blade directives.

---

Additional Fixes and Improvements
---------------------------------

- Redis queue driver is now cluster-safe (`bulk()` uses node-less `MULTI`; `allQueueNames()` uses `KEYS`).
- `lazy()` and `lazyById()` no longer ignore `limit()` and `offset()`.
- `assertJsonMissingPath()` now correctly handles wildcards.
- Memory leak fix in the HTTP client.
- `UsePolicy` and `UseEloquentBuilder` attributes now resolve from parent classes.
- `RateLimited` job middleware no longer hits limits that should not block the job.
- Context is now correctly propagated to concurrent processes.

---

Key Takeaways
-------------

- **`Queue::totalSize()`** replaces three separate calls with one.
- **`JobInterrupted`** event enables first-class cleanup hooks for interruptible jobs.
- **`BelongsToMany` chaperone** eliminates redundant queries when using custom pivot models with `BelongsTo` relations.
- **`assertSentOnce` / `assertQueuedOnce`** make test assertions more readable.
- **`Vite::devServerUrl()`** exposes the dev server URL as a first-class API.

---

[View the full Laravel 13.31.0 release notes and diff on Laravel News →](https://laravel-news.com/laravel-13-31-0)

 Found this useful?

          [  ](https://twitter.com/intent/tweet?url=https%3A%2F%2Fwww.msaied.com%2Farticles%2Fqueue-totalsize-and-jobinterrupted-event-in-laravel-1331&text=Queue+totalSize%28%29+and+JobInterrupted+Event+in+Laravel+13.31) [  ](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fwww.msaied.com%2Farticles%2Fqueue-totalsize-and-jobinterrupted-event-in-laravel-1331) 

 Frequently Asked Questions 
----------------------------

  3 questions  

     Q01  What does Queue::totalSize() return in Laravel 13.31?        It returns the combined count of all jobs on a queue connection — pending, delayed, and reserved — in a single method call, replacing the need to manually sum Queue::totalPendingSize(), Queue::totalDelayedSize(), and Queue::totalReservedSize(). 

      Q02  When does the JobInterrupted event fire in Laravel?        The JobInterrupted event fires when a job that implements the Interruptible contract is interrupted by the queue worker. You can listen for it to run cleanup logic, flush state, or log the interruption. 

      Q03  What does calling -&gt;chaperone() on a BelongsToMany relationship do?        When a custom pivot model defines BelongsTo relations back to the parent and related models, chaperone() hydrates those relations from already-loaded instances during BelongsToMany hydration, avoiding extra database queries. If no custom pivot model is used, it is a no-op. 

  Continue reading

 More Articles 
---------------

 [ View all    ](https://www.msaied.com/articles) 

 [ ![Event Sourcing in Laravel: Aggregates, Projectors, and Rebuilding Read Models](https://cdn.msaied.com/647/586a0f822614fed8091917a895ebc502.png) laravel event-sourcing ddd 

### Event Sourcing in Laravel: Aggregates, Projectors, and Rebuilding Read Models

A practical walkthrough of event sourcing in Laravel — defining aggregates, persisting domain events, building...

  ![Mohamed Said](https://cdn.msaied.com/01M22N44A70A5MC2S599JP0MPH.webp)  Mohamed Said 

 9 Sep 2026     3 min read  

  Read    

 ](https://www.msaied.com/articles/event-sourcing-in-laravel-aggregates-projectors-and-rebuilding-read-models) [ ![Read/Write Splitting and Sticky Reads in Laravel: A Production Guide](https://cdn.msaied.com/646/4155b1eed8a491a99c3dda6f7dddd80e.png) laravel database performance 

### Read/Write Splitting and Sticky Reads in Laravel: A Production Guide

Learn how Laravel's read/write connection splitting works under the hood, when sticky reads save you from repl...

  ![Mohamed Said](https://cdn.msaied.com/01M22N44A70A5MC2S599JP0MPH.webp)  Mohamed Said 

 9 Sep 2026     3 min read  

  Read    

 ](https://www.msaied.com/articles/readwrite-splitting-and-sticky-reads-in-laravel-a-production-guide) [ ![Chunked Iteration, Lazy Collections, and Cursor Pagination at Scale in Laravel](https://cdn.msaied.com/645/3bcda55cd0d9e4e9b4be38c9b3d11ea4.png) laravel eloquent performance 

### Chunked Iteration, Lazy Collections, and Cursor Pagination at Scale in Laravel

Processing millions of Eloquent rows without exhausting memory requires the right tool for the job. Learn when...

  ![Mohamed Said](https://cdn.msaied.com/01M22N44A70A5MC2S599JP0MPH.webp)  Mohamed Said 

 8 Sep 2026     4 min read  

  Read    

 ](https://www.msaied.com/articles/chunked-iteration-lazy-collections-and-cursor-pagination-at-scale-in-laravel) 

   [  ![Mohamed Said](https://cdn.msaied.com/01KT78WE565VEMM3PSNQAAB0MH.png)   Mohamed Said Laravel Backend Engineer  ](https://www.msaied.com)Senior Backend Engineer specializing in Laravel, scalable SaaS platforms, APIs, and cloud infrastructure. I build secure, high-performance web applications that help businesses grow.

Explore

- [Home](https://www.msaied.com)
- [Projects](https://www.msaied.com/projects)
- [Articles](https://www.msaied.com/articles)
- [Certificates](https://www.msaied.com/certificates)
- [Contact](https://www.msaied.com#contact-section)

Connect

- [   hello@msaied.com ](mailto:hello@msaied.com)
- [   +20 109 461 9204 ](tel:+201094619204)

© 2026 Mohamed Said. All rights reserved.

 [  ](https://github.com/EG-Mohamed) [  ](https://www.linkedin.com/in/msaiedm/) [  ](https://wa.me/201094619204) [  ](mailto:hello@msaied.com) [  ](https://drive.google.com/file/u/0/d/1MF20IPRJyzfy32mhEutjL5EpSls0w2Q8/view)
