Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.4] Add ability to set queue parameters from within a queued listener #18375

Merged
merged 2 commits into from
Mar 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/Illuminate/Events/CallQueuedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
16 changes: 13 additions & 3 deletions src/Illuminate/Events/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -452,13 +452,23 @@ 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;

$this->resolveQueue()
->connection($connection)
->pushOn($queue, new CallQueuedListener($class, $method, $arguments));
$job->tries = isset($listener->tries) ? $listener->tries : null;

$job->timeout = isset($listener->timeout) ? $listener->timeout : null;

$resolvedQueue = $this->resolveQueue()->connection($connection);

if (isset($listener->delay)) {
$resolvedQueue->laterOn($queue, $listener->delay, $job);
} else {
$resolvedQueue->pushOn($queue, $job);
}
}

/**
Expand Down