Skip to content

Commit 1f8e156

Browse files
authored
Allow dynamic tries() method on Queueable listeners (#57014)
1 parent 33d3fc9 commit 1f8e156

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/Illuminate/Events/Dispatcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ protected function propagateListenerOptions($listener, $job)
705705
$job->shouldBeEncrypted = $listener instanceof ShouldBeEncrypted;
706706
$job->timeout = $listener->timeout ?? null;
707707
$job->failOnTimeout = $listener->failOnTimeout ?? false;
708-
$job->tries = $listener->tries ?? null;
708+
$job->tries = method_exists($listener, 'tries') ? $listener->tries(...$data) : ($listener->tries ?? null);
709709

710710
$job->through(array_merge(
711711
method_exists($listener, 'middleware') ? $listener->middleware(...$data) : [],

tests/Events/QueuedEventsTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,24 @@ public function testQueuePropagateRetryUntilAndMaxExceptions()
179179
});
180180
}
181181

182+
public function testQueuePropagateTries()
183+
{
184+
$d = new Dispatcher;
185+
186+
$fakeQueue = new QueueFake(new Container);
187+
188+
$d->setQueueResolver(function () use ($fakeQueue) {
189+
return $fakeQueue;
190+
});
191+
192+
$d->listen('some.event', TestDispatcherOptions::class.'@handle');
193+
$d->dispatch('some.event', ['foo', 'bar']);
194+
195+
$fakeQueue->assertPushed(CallQueuedListener::class, function ($job) {
196+
return $job->tries === 5;
197+
});
198+
}
199+
182200
public function testQueuePropagateMiddleware()
183201
{
184202
$d = new Dispatcher;
@@ -294,6 +312,11 @@ public function retryUntil()
294312
return now()->addHour(1);
295313
}
296314

315+
public function tries()
316+
{
317+
return 5;
318+
}
319+
297320
public function handle()
298321
{
299322
//

0 commit comments

Comments
 (0)