Skip to content

Commit be53be9

Browse files
committed
document shared lock keys
1 parent d0ee784 commit be53be9

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

queues.md

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ For example, let's imagine you have a queued job that updates a user's credit sc
508508
return [new WithoutOverlapping($this->user->id)];
509509
}
510510

511-
Any overlapping jobs will be released back to the queue. You may also specify the number of seconds that must elapse before the released job will be attempted again:
511+
Any overlapping jobs of the same type will be released back to the queue. You may also specify the number of seconds that must elapse before the released job will be attempted again:
512512

513513
/**
514514
* Get the middleware the job should pass through.
@@ -544,9 +544,44 @@ The `WithoutOverlapping` middleware is powered by Laravel's atomic lock feature.
544544
return [(new WithoutOverlapping($this->order->id))->expireAfter(180)];
545545
}
546546

547-
> **Warning**
547+
> **Warning**
548548
> The `WithoutOverlapping` middleware requires a cache driver that supports [locks](/docs/{{version}}/cache#atomic-locks). Currently, the `memcached`, `redis`, `dynamodb`, `database`, `file`, and `array` cache drivers support atomic locks.
549549
550+
<a name="sharing-lock-keys"></a>
551+
#### Sharing Lock Keys Across Job Classes
552+
553+
By default, the `WithoutOverlapping` middleware will only prevent overlapping jobs of the same class. So, although two different job classes may use the same lock key, they will not be prevented from overlapping. However, you can instruct Laravel to apply the key across job classes using the `shared` method:
554+
555+
```php
556+
use Illuminate\Queue\Middleware\WithoutOverlapping;
557+
558+
class ProviderIsDown
559+
{
560+
// ...
561+
562+
563+
public function middleware()
564+
{
565+
return [
566+
(new WithoutOverlapping("status:{$this->provider}"))->shared(),
567+
];
568+
}
569+
}
570+
571+
class ProviderIsUp
572+
{
573+
// ...
574+
575+
576+
public function middleware()
577+
{
578+
return [
579+
(new WithoutOverlapping("status:{$this->provider}"))->shared(),
580+
];
581+
}
582+
}
583+
```
584+
550585
<a name="throttling-exceptions"></a>
551586
### Throttling Exceptions
552587

0 commit comments

Comments
 (0)