Skip to content

Commit 87ad498

Browse files
committed
Allow dynamic tries() method on Queueable listeners
1 parent 7b5e185 commit 87ad498

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-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: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,25 @@ 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+
200+
182201
public function testQueuePropagateMiddleware()
183202
{
184203
$d = new Dispatcher;
@@ -294,6 +313,11 @@ public function retryUntil()
294313
return now()->addHour(1);
295314
}
296315

316+
public function tries()
317+
{
318+
return 5;
319+
}
320+
297321
public function handle()
298322
{
299323
//

0 commit comments

Comments
 (0)