Laravel 5.6 updates

Travis config update

Removed HHVM script as Laravel no longer support HHVM after releasing 5.3
This commit is contained in:
Manish Verma
2018-08-06 20:08:55 +05:30
parent 126fbb0255
commit 1ac0f42a58
2464 changed files with 65239 additions and 46734 deletions

View File

@@ -85,7 +85,7 @@ class CallQueuedHandler
*/
protected function setJobInstanceIfNecessary(Job $job, $instance)
{
if (in_array(InteractsWithQueue::class, class_uses_recursive(get_class($instance)))) {
if (in_array(InteractsWithQueue::class, class_uses_recursive($instance))) {
$instance->setJob($job);
}

View File

@@ -45,7 +45,8 @@ class RedisConnector implements ConnectorInterface
return new RedisQueue(
$this->redis, $config['queue'],
$config['connection'] ?? $this->connection,
$config['retry_after'] ?? 60
$config['retry_after'] ?? 60,
$config['block_for'] ?? null
);
}
}

View File

@@ -19,7 +19,7 @@ class SqsConnector implements ConnectorInterface
$config = $this->getDefaultConfiguration($config);
if ($config['key'] && $config['secret']) {
$config['credentials'] = Arr::only($config, ['key', 'secret']);
$config['credentials'] = Arr::only($config, ['key', 'secret', 'token']);
}
return new SqsQueue(

View File

@@ -168,8 +168,9 @@ class WorkCommand extends Command
protected function writeStatus(Job $job, $status, $type)
{
$this->output->writeln(sprintf(
"<{$type}>[%s] %s</{$type}> %s",
"<{$type}>[%s][%s] %s</{$type}> %s",
Carbon::now()->format('Y-m-d H:i:s'),
$job->getJobId(),
str_pad("{$status}:", 11), $job->resolveName()
));
}

View File

@@ -2,7 +2,6 @@
namespace Illuminate\Queue;
use Throwable;
use Illuminate\Support\Carbon;
use Illuminate\Database\Connection;
use Illuminate\Queue\Jobs\DatabaseJob;
@@ -191,19 +190,13 @@ class DatabaseQueue extends Queue implements QueueContract
{
$queue = $this->getQueue($queue);
try {
$this->database->beginTransaction();
return $this->database->transaction(function () use ($queue) {
if ($job = $this->getNextAvailableJob($queue)) {
return $this->marshalJob($queue, $job);
}
$this->database->commit();
} catch (Throwable $e) {
$this->database->rollBack();
throw $e;
}
return null;
});
}
/**
@@ -267,8 +260,6 @@ class DatabaseQueue extends Queue implements QueueContract
{
$job = $this->markJobAsReserved($job);
$this->database->commit();
return new DatabaseJob(
$this->container, $this, $job, $this->connectionName, $queue
);

View File

@@ -55,6 +55,13 @@ abstract class Job
*/
protected $queue;
/**
* Get the job identifier.
*
* @return string
*/
abstract public function getJobId();
/**
* Get the raw body of the job.
*

View File

@@ -96,7 +96,7 @@ class Listener
{
return defined('ARTISAN_BINARY')
? ProcessUtils::escapeArgument(ARTISAN_BINARY)
: 'artisan';
: ProcessUtils::escapeArgument('artisan');
}
/**

View File

@@ -17,13 +17,6 @@ abstract class Queue
*/
protected $container;
/**
* The encrypter implementation.
*
* @var \Illuminate\Contracts\Encryption\Encrypter
*/
protected $encrypter;
/**
* The connection name for the queue.
*

View File

@@ -37,6 +37,13 @@ class RedisQueue extends Queue implements QueueContract
*/
protected $retryAfter = 60;
/**
* The maximum number of seconds to block for a job.
*
* @var int|null
*/
protected $blockFor = null;
/**
* Create a new Redis queue instance.
*
@@ -44,12 +51,14 @@ class RedisQueue extends Queue implements QueueContract
* @param string $default
* @param string $connection
* @param int $retryAfter
* @param int|null $blockFor
* @return void
*/
public function __construct(Redis $redis, $default = 'default', $connection = null, $retryAfter = 60)
public function __construct(Redis $redis, $default = 'default', $connection = null, $retryAfter = 60, $blockFor = null)
{
$this->redis = $redis;
$this->default = $default;
$this->blockFor = $blockFor;
$this->connection = $connection;
$this->retryAfter = $retryAfter;
}
@@ -200,12 +209,43 @@ class RedisQueue extends Queue implements QueueContract
*/
protected function retrieveNextJob($queue)
{
if (! is_null($this->blockFor)) {
return $this->blockingPop($queue);
}
return $this->getConnection()->eval(
LuaScripts::pop(), 2, $queue, $queue.':reserved',
$this->availableAt($this->retryAfter)
);
}
/**
* Retrieve the next job by blocking-pop.
*
* @param string $queue
* @return array
*/
protected function blockingPop($queue)
{
$rawBody = $this->getConnection()->blpop($queue, $this->blockFor);
if (! empty($rawBody)) {
$payload = json_decode($rawBody[1], true);
$payload['attempts']++;
$reserved = json_encode($payload);
$this->getConnection()->zadd($queue.':reserved', [
$reserved => $this->availableAt($this->retryAfter),
]);
return [$rawBody[1], $reserved];
}
return [null, null];
}
/**
* Delete a reserved job from the queue.
*

View File

@@ -21,6 +21,7 @@ trait SerializesAndRestoresModelIdentifiers
return new ModelIdentifier(
$value->getQueueableClass(),
$value->getQueueableIds(),
$value->getQueueableRelations(),
$value->getQueueableConnection()
);
}
@@ -29,6 +30,7 @@ trait SerializesAndRestoresModelIdentifiers
return new ModelIdentifier(
get_class($value),
$value->getQueueableId(),
$value->getQueueableRelations(),
$value->getQueueableConnection()
);
}
@@ -50,8 +52,7 @@ trait SerializesAndRestoresModelIdentifiers
return is_array($value->id)
? $this->restoreCollection($value)
: $this->getQueryForModelRestoration((new $value->class)->setConnection($value->connection), $value->id)
->useWritePdo()->firstOrFail();
: $this->restoreModel($value);
}
/**
@@ -72,10 +73,23 @@ trait SerializesAndRestoresModelIdentifiers
}
/**
* Get the query for restoration.
* Restore the model from the model identifier instance.
*
* @param \Illuminate\Contracts\Database\ModelIdentifier $value
* @return \Illuminate\Database\Eloquent\Model
*/
public function restoreModel($value)
{
return $this->getQueryForModelRestoration(
(new $value->class)->setConnection($value->connection), $value->id
)->useWritePdo()->firstOrFail()->load($value->relations ?? []);
}
/**
* Get the query for model restoration.
*
* @param \Illuminate\Database\Eloquent\Model $model
* @param array|int $ids
* @param array|int $ids
* @return \Illuminate\Database\Eloquent\Builder
*/
protected function getQueryForModelRestoration($model, $ids)

View File

@@ -24,9 +24,9 @@ trait SerializesModels
));
}
return array_map(function ($p) {
return $p->getName();
}, $properties);
return array_values(array_filter(array_map(function ($p) {
return $p->isStatic() ? null : $p->getName();
}, $properties)));
}
/**
@@ -37,6 +37,10 @@ trait SerializesModels
public function __wakeup()
{
foreach ((new ReflectionClass($this))->getProperties() as $property) {
if ($property->isStatic()) {
continue;
}
$property->setValue($this, $this->getRestoredPropertyValue(
$this->getPropertyValue($property)
));

View File

@@ -84,7 +84,9 @@ class Worker
*/
public function daemon($connectionName, $queue, WorkerOptions $options)
{
$this->listenForSignals();
if ($this->supportsAsyncSignals()) {
$this->listenForSignals();
}
$lastRestart = $this->getTimestampOfLastQueueRestart();
@@ -105,7 +107,9 @@ class Worker
$this->manager->connection($connectionName), $queue
);
$this->registerTimeoutHandler($job, $options);
if ($this->supportsAsyncSignals()) {
$this->registerTimeoutHandler($job, $options);
}
// If the daemon should run (not in maintenance mode, etc.), then we can run
// fire off this job for processing. Otherwise, we will need to sleep the
@@ -124,7 +128,7 @@ class Worker
}
/**
* Register the worker timeout handler (PHP 7.1+).
* Register the worker timeout handler.
*
* @param \Illuminate\Contracts\Queue\Job|null $job
* @param \Illuminate\Queue\WorkerOptions $options
@@ -132,18 +136,16 @@ class Worker
*/
protected function registerTimeoutHandler($job, WorkerOptions $options)
{
if ($this->supportsAsyncSignals()) {
// We will register a signal handler for the alarm signal so that we can kill this
// process if it is running too long because it has frozen. This uses the async
// signals supported in recent versions of PHP to accomplish it conveniently.
pcntl_signal(SIGALRM, function () {
$this->kill(1);
});
// We will register a signal handler for the alarm signal so that we can kill this
// process if it is running too long because it has frozen. This uses the async
// signals supported in recent versions of PHP to accomplish it conveniently.
pcntl_signal(SIGALRM, function () {
$this->kill(1);
});
pcntl_alarm(
max($this->timeoutForJob($job, $options), 0)
);
}
pcntl_alarm(
max($this->timeoutForJob($job, $options), 0)
);
}
/**
@@ -282,7 +284,7 @@ class Worker
/**
* Stop the worker if we have lost connection to a database.
*
* @param \Exception $e
* @param \Throwable $e
* @return void
*/
protected function stopWorkerIfLostConnection($e)
@@ -476,21 +478,6 @@ class Worker
));
}
/**
* Raise the failed queue job event.
*
* @param string $connectionName
* @param \Illuminate\Contracts\Queue\Job $job
* @param \Exception $e
* @return void
*/
protected function raiseFailedJobEvent($connectionName, $job, $e)
{
$this->events->dispatch(new Events\JobFailed(
$connectionName, $job, $e
));
}
/**
* Determine if the queue worker should restart.
*
@@ -521,21 +508,19 @@ class Worker
*/
protected function listenForSignals()
{
if ($this->supportsAsyncSignals()) {
pcntl_async_signals(true);
pcntl_async_signals(true);
pcntl_signal(SIGTERM, function () {
$this->shouldQuit = true;
});
pcntl_signal(SIGTERM, function () {
$this->shouldQuit = true;
});
pcntl_signal(SIGUSR2, function () {
$this->paused = true;
});
pcntl_signal(SIGUSR2, function () {
$this->paused = true;
});
pcntl_signal(SIGCONT, function () {
$this->paused = false;
});
}
pcntl_signal(SIGCONT, function () {
$this->paused = false;
});
}
/**
@@ -545,8 +530,7 @@ class Worker
*/
protected function supportsAsyncSignals()
{
return version_compare(PHP_VERSION, '7.1.0') >= 0 &&
extension_loaded('pcntl');
return extension_loaded('pcntl');
}
/**

View File

@@ -14,15 +14,15 @@
}
],
"require": {
"php": ">=7.0",
"illuminate/console": "5.5.*",
"illuminate/container": "5.5.*",
"illuminate/contracts": "5.5.*",
"illuminate/database": "5.5.*",
"illuminate/filesystem": "5.5.*",
"illuminate/support": "5.5.*",
"symfony/debug": "~3.3",
"symfony/process": "~3.3"
"php": "^7.1.3",
"illuminate/console": "5.6.*",
"illuminate/container": "5.6.*",
"illuminate/contracts": "5.6.*",
"illuminate/database": "5.6.*",
"illuminate/filesystem": "5.6.*",
"illuminate/support": "5.6.*",
"symfony/debug": "~4.0",
"symfony/process": "~4.0"
},
"autoload": {
"psr-4": {
@@ -31,14 +31,14 @@
},
"extra": {
"branch-alias": {
"dev-master": "5.5-dev"
"dev-master": "5.6-dev"
}
},
"suggest": {
"ext-pcntl": "Required to use all features of the queue worker.",
"ext-posix": "Required to use all features of the queue worker.",
"aws/aws-sdk-php": "Required to use the SQS queue driver (~3.0).",
"illuminate/redis": "Required to use the Redis queue driver (5.5.*).",
"illuminate/redis": "Required to use the Redis queue driver (5.6.*).",
"pda/pheanstalk": "Required to use the Beanstalk queue driver (~3.0)."
},
"config": {