Skip to content

Commit f464107

Browse files
authored
[12.x] Add documentation about queued notification job properties (#10852)
* Document queued notification job properties Add documentation explaining that queued notifications inherit job-related properties (tries, timeout, maxExceptions, shouldBeEncrypted, backoff, retryUntil) from the notification class to the underlying queued job. This behavior is implemented in SendQueuedNotifications but was not previously documented. * Fix: Use ShouldBeEncrypted interface instead of property The shouldBeEncrypted behavior is applied by implementing the ShouldBeEncrypted interface on the notification class, not by setting a property directly. * Remove menu item and adjust wording * Remove unnecessary sentence
1 parent e076ea1 commit f464107

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

notifications.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,94 @@ public function viaQueues(): array
275275
}
276276
```
277277

278+
<a name="customizing-queued-notification-job-properties"></a>
279+
#### Customizing Queued Notification Job Properties
280+
281+
You may customize the behavior of the underlying queued job by defining properties on your notification class. These properties will be inherited by the queued job that sends the notification:
282+
283+
```php
284+
<?php
285+
286+
namespace App\Notifications;
287+
288+
use Illuminate\Bus\Queueable;
289+
use Illuminate\Contracts\Queue\ShouldQueue;
290+
use Illuminate\Notifications\Notification;
291+
292+
class InvoicePaid extends Notification implements ShouldQueue
293+
{
294+
use Queueable;
295+
296+
/**
297+
* The number of times the notification may be attempted.
298+
*
299+
* @var int
300+
*/
301+
public $tries = 5;
302+
303+
/**
304+
* The number of seconds the notification can run before timing out.
305+
*
306+
* @var int
307+
*/
308+
public $timeout = 120;
309+
310+
/**
311+
* The maximum number of unhandled exceptions to allow before failing.
312+
*
313+
* @var int
314+
*/
315+
public $maxExceptions = 3;
316+
317+
// ...
318+
}
319+
```
320+
321+
If you would like to ensure the privacy and integrity of a queued notification's data via [encryption](/docs/{{version}}/encryption), add the `ShouldBeEncrypted` interface to your notification class:
322+
323+
```php
324+
<?php
325+
326+
namespace App\Notifications;
327+
328+
use Illuminate\Bus\Queueable;
329+
use Illuminate\Contracts\Queue\ShouldBeEncrypted;
330+
use Illuminate\Contracts\Queue\ShouldQueue;
331+
use Illuminate\Notifications\Notification;
332+
333+
class InvoicePaid extends Notification implements ShouldQueue, ShouldBeEncrypted
334+
{
335+
use Queueable;
336+
337+
// ...
338+
}
339+
```
340+
341+
In addition to defining these properties directly on your notification class, you may also define `backoff` and `retryUntil` methods to specify the backoff strategy and retry timeout for the queued notification job:
342+
343+
```php
344+
use DateTime;
345+
346+
/**
347+
* Calculate the number of seconds to wait before retrying the notification.
348+
*/
349+
public function backoff(): int
350+
{
351+
return 3;
352+
}
353+
354+
/**
355+
* Determine the time at which the notification should timeout.
356+
*/
357+
public function retryUntil(): DateTime
358+
{
359+
return now()->addMinutes(5);
360+
}
361+
```
362+
363+
> [!NOTE]
364+
> For more information on these job properties and methods, please review the documentation on [queued jobs](/docs/{{version}}/queues#max-job-attempts-and-timeout).
365+
278366
<a name="queued-notification-middleware"></a>
279367
#### Queued Notification Middleware
280368

0 commit comments

Comments
 (0)