package updates
This commit is contained in:
@@ -29,7 +29,7 @@ class CallQueuedClosure implements ShouldQueue
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param \Illuminate\Queue\SerializableClosure
|
||||
* @param \Illuminate\Queue\SerializableClosure $closure
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(SerializableClosure $closure)
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ class ListFailedCommand extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
if (count($jobs = $this->getFailedJobs()) == 0) {
|
||||
if (count($jobs = $this->getFailedJobs()) === 0) {
|
||||
return $this->info('No failed jobs!');
|
||||
}
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ abstract class Job
|
||||
{
|
||||
$payload = $this->payload();
|
||||
|
||||
list($class, $method) = JobName::parse($payload['job']);
|
||||
[$class, $method] = JobName::parse($payload['job']);
|
||||
|
||||
($this->instance = $this->resolve($class))->{$method}($this, $payload['data']);
|
||||
}
|
||||
@@ -166,7 +166,7 @@ abstract class Job
|
||||
|
||||
$payload = $this->payload();
|
||||
|
||||
list($class, $method) = JobName::parse($payload['job']);
|
||||
[$class, $method] = JobName::parse($payload['job']);
|
||||
|
||||
if (method_exists($this->instance = $this->resolve($class), 'failed')) {
|
||||
$this->instance->failed($payload['data'], $e);
|
||||
|
||||
@@ -120,7 +120,7 @@ class RedisJob extends Job implements JobContract
|
||||
/**
|
||||
* Get the underlying Redis factory implementation.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Redis\Factory
|
||||
* @return \Illuminate\Queue\RedisQueue
|
||||
*/
|
||||
public function getRedisQueue()
|
||||
{
|
||||
|
||||
+32
-50
@@ -3,7 +3,6 @@
|
||||
namespace Illuminate\Queue;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Support\ProcessUtils;
|
||||
use Symfony\Component\Process\Process;
|
||||
use Symfony\Component\Process\PhpExecutableFinder;
|
||||
|
||||
@@ -37,13 +36,6 @@ class Listener
|
||||
*/
|
||||
protected $maxTries = 0;
|
||||
|
||||
/**
|
||||
* The queue worker command line.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $workerCommand;
|
||||
|
||||
/**
|
||||
* The output handler callback.
|
||||
*
|
||||
@@ -60,19 +52,6 @@ class Listener
|
||||
public function __construct($commandPath)
|
||||
{
|
||||
$this->commandPath = $commandPath;
|
||||
$this->workerCommand = $this->buildCommandTemplate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the environment specific worker command.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function buildCommandTemplate()
|
||||
{
|
||||
$command = 'queue:work %s --once --queue=%s --delay=%s --memory=%s --sleep=%s --tries=%s';
|
||||
|
||||
return "{$this->phpBinary()} {$this->artisanBinary()} {$command}";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,9 +61,7 @@ class Listener
|
||||
*/
|
||||
protected function phpBinary()
|
||||
{
|
||||
return ProcessUtils::escapeArgument(
|
||||
(new PhpExecutableFinder)->find(false)
|
||||
);
|
||||
return (new PhpExecutableFinder)->find(false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -94,9 +71,7 @@ class Listener
|
||||
*/
|
||||
protected function artisanBinary()
|
||||
{
|
||||
return defined('ARTISAN_BINARY')
|
||||
? ProcessUtils::escapeArgument(ARTISAN_BINARY)
|
||||
: ProcessUtils::escapeArgument('artisan');
|
||||
return defined('ARTISAN_BINARY') ? ARTISAN_BINARY : 'artisan';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -126,24 +101,25 @@ class Listener
|
||||
*/
|
||||
public function makeProcess($connection, $queue, ListenerOptions $options)
|
||||
{
|
||||
$command = $this->workerCommand;
|
||||
$command = $this->createCommand(
|
||||
$connection,
|
||||
$queue,
|
||||
$options
|
||||
);
|
||||
|
||||
// If the environment is set, we will append it to the command string so the
|
||||
// If the environment is set, we will append it to the command array so the
|
||||
// workers will run under the specified environment. Otherwise, they will
|
||||
// just run under the production environment which is not always right.
|
||||
if (isset($options->environment)) {
|
||||
$command = $this->addEnvironment($command, $options);
|
||||
}
|
||||
|
||||
// Next, we will just format out the worker commands with all of the various
|
||||
// options available for the command. This will produce the final command
|
||||
// line that we will pass into a Symfony process object for processing.
|
||||
$command = $this->formatCommand(
|
||||
$command, $connection, $queue, $options
|
||||
);
|
||||
|
||||
return new Process(
|
||||
$command, $this->commandPath, null, null, $options->timeout
|
||||
$command,
|
||||
$this->commandPath,
|
||||
null,
|
||||
null,
|
||||
$options->timeout
|
||||
);
|
||||
}
|
||||
|
||||
@@ -152,31 +128,37 @@ class Listener
|
||||
*
|
||||
* @param string $command
|
||||
* @param \Illuminate\Queue\ListenerOptions $options
|
||||
* @return string
|
||||
* @return array
|
||||
*/
|
||||
protected function addEnvironment($command, ListenerOptions $options)
|
||||
{
|
||||
return $command.' --env='.ProcessUtils::escapeArgument($options->environment);
|
||||
return array_merge($command, ["--env={$options->environment}"]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the given command with the listener options.
|
||||
* Create the command with the listener options.
|
||||
*
|
||||
* @param string $command
|
||||
* @param string $connection
|
||||
* @param string $queue
|
||||
* @param \Illuminate\Queue\ListenerOptions $options
|
||||
* @return string
|
||||
* @return array
|
||||
*/
|
||||
protected function formatCommand($command, $connection, $queue, ListenerOptions $options)
|
||||
protected function createCommand($connection, $queue, ListenerOptions $options)
|
||||
{
|
||||
return sprintf(
|
||||
$command,
|
||||
ProcessUtils::escapeArgument($connection),
|
||||
ProcessUtils::escapeArgument($queue),
|
||||
$options->delay, $options->memory,
|
||||
$options->sleep, $options->maxTries
|
||||
);
|
||||
return array_filter([
|
||||
$this->phpBinary(),
|
||||
$this->artisanBinary(),
|
||||
'queue:work',
|
||||
$connection,
|
||||
'--once',
|
||||
"--queue={$queue}",
|
||||
"--delay={$options->delay}",
|
||||
"--memory={$options->memory}",
|
||||
"--sleep={$options->sleep}",
|
||||
"--tries={$options->maxTries}",
|
||||
], function ($value) {
|
||||
return ! is_null($value);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+15
-9
@@ -25,11 +25,11 @@ abstract class Queue
|
||||
protected $connectionName;
|
||||
|
||||
/**
|
||||
* The create payload callback.
|
||||
* The create payload callbacks.
|
||||
*
|
||||
* @var callable|null
|
||||
* @var callable[]
|
||||
*/
|
||||
protected static $createPayloadCallback;
|
||||
protected static $createPayloadCallbacks = [];
|
||||
|
||||
/**
|
||||
* Push a new job onto the queue.
|
||||
@@ -64,7 +64,7 @@ abstract class Queue
|
||||
* @param array $jobs
|
||||
* @param mixed $data
|
||||
* @param string $queue
|
||||
* @return mixed
|
||||
* @return void
|
||||
*/
|
||||
public function bulk($jobs, $data = '', $queue = null)
|
||||
{
|
||||
@@ -197,7 +197,11 @@ abstract class Queue
|
||||
*/
|
||||
public static function createPayloadUsing($callback)
|
||||
{
|
||||
static::$createPayloadCallback = $callback;
|
||||
if (is_null($callback)) {
|
||||
static::$createPayloadCallbacks = [];
|
||||
} else {
|
||||
static::$createPayloadCallbacks[] = $callback;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -209,10 +213,12 @@ abstract class Queue
|
||||
*/
|
||||
protected function withCreatePayloadHooks($queue, array $payload)
|
||||
{
|
||||
if (static::$createPayloadCallback) {
|
||||
return array_merge($payload, call_user_func(
|
||||
static::$createPayloadCallback, $this->getConnectionName(), $queue, $payload
|
||||
));
|
||||
if (! empty(static::$createPayloadCallbacks)) {
|
||||
foreach (static::$createPayloadCallbacks as $callback) {
|
||||
$payload = array_merge($payload, call_user_func(
|
||||
$callback, $this->getConnectionName(), $queue, $payload
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
return $payload;
|
||||
|
||||
@@ -167,7 +167,7 @@ class RedisQueue extends Queue implements QueueContract
|
||||
return;
|
||||
}
|
||||
|
||||
list($job, $reserved) = $nextJob;
|
||||
[$job, $reserved] = $nextJob;
|
||||
|
||||
if ($reserved) {
|
||||
return new RedisJob(
|
||||
|
||||
Reference in New Issue
Block a user