From deae6c7e043751c52b000b4ce2982445faa44eea Mon Sep 17 00:00:00 2001 From: Mohamed Said Date: Thu, 16 Mar 2017 14:05:56 +0200 Subject: [PATCH 1/2] allow setting tries and timeout inside a listener --- src/Illuminate/Events/CallQueuedListener.php | 14 ++++++++++++++ src/Illuminate/Events/Dispatcher.php | 8 +++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Events/CallQueuedListener.php b/src/Illuminate/Events/CallQueuedListener.php index b362dd6c13a2..381d5043c97b 100644 --- a/src/Illuminate/Events/CallQueuedListener.php +++ b/src/Illuminate/Events/CallQueuedListener.php @@ -32,6 +32,20 @@ class CallQueuedListener implements ShouldQueue */ public $data; + /** + * The number of times the job may be attempted. + * + * @var int + */ + public $tries; + + /** + * The number of seconds the job can run before timing out. + * + * @var int + */ + public $timeout; + /** * Create a new job instance. * diff --git a/src/Illuminate/Events/Dispatcher.php b/src/Illuminate/Events/Dispatcher.php index 256c07491da4..a3bdff676cf3 100755 --- a/src/Illuminate/Events/Dispatcher.php +++ b/src/Illuminate/Events/Dispatcher.php @@ -452,13 +452,19 @@ protected function queueHandler($class, $method, $arguments) { $listener = (new ReflectionClass($class))->newInstanceWithoutConstructor(); + $job = new CallQueuedListener($class, $method, $arguments); + $connection = isset($listener->connection) ? $listener->connection : null; $queue = isset($listener->queue) ? $listener->queue : null; + $job->tries = isset($listener->tries) ? $listener->tries : null; + + $job->timeout = isset($listener->timeout) ? $listener->timeout : null; + $this->resolveQueue() ->connection($connection) - ->pushOn($queue, new CallQueuedListener($class, $method, $arguments)); + ->pushOn($queue, $job); } /** From c6c0c9efcc0cf1c407256be6596234decd703152 Mon Sep 17 00:00:00 2001 From: Mohamed Said Date: Thu, 16 Mar 2017 14:20:28 +0200 Subject: [PATCH 2/2] allow delay as well --- src/Illuminate/Events/Dispatcher.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Events/Dispatcher.php b/src/Illuminate/Events/Dispatcher.php index a3bdff676cf3..5185e33a33b8 100755 --- a/src/Illuminate/Events/Dispatcher.php +++ b/src/Illuminate/Events/Dispatcher.php @@ -462,9 +462,13 @@ protected function queueHandler($class, $method, $arguments) $job->timeout = isset($listener->timeout) ? $listener->timeout : null; - $this->resolveQueue() - ->connection($connection) - ->pushOn($queue, $job); + $resolvedQueue = $this->resolveQueue()->connection($connection); + + if (isset($listener->delay)) { + $resolvedQueue->laterOn($queue, $listener->delay, $job); + } else { + $resolvedQueue->pushOn($queue, $job); + } } /**