Primo Committ
This commit is contained in:
172
vendor/laravel/framework/src/Illuminate/Queue/BeanstalkdQueue.php
vendored
Executable file
172
vendor/laravel/framework/src/Illuminate/Queue/BeanstalkdQueue.php
vendored
Executable file
@@ -0,0 +1,172 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Queue;
|
||||
|
||||
use Illuminate\Contracts\Queue\Queue as QueueContract;
|
||||
use Illuminate\Queue\Jobs\BeanstalkdJob;
|
||||
use Pheanstalk\Job as PheanstalkJob;
|
||||
use Pheanstalk\Pheanstalk;
|
||||
|
||||
class BeanstalkdQueue extends Queue implements QueueContract
|
||||
{
|
||||
/**
|
||||
* The Pheanstalk instance.
|
||||
*
|
||||
* @var \Pheanstalk\Pheanstalk
|
||||
*/
|
||||
protected $pheanstalk;
|
||||
|
||||
/**
|
||||
* The name of the default tube.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $default;
|
||||
|
||||
/**
|
||||
* The "time to run" for all pushed jobs.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $timeToRun;
|
||||
|
||||
/**
|
||||
* The maximum number of seconds to block for a job.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $blockFor;
|
||||
|
||||
/**
|
||||
* Create a new Beanstalkd queue instance.
|
||||
*
|
||||
* @param \Pheanstalk\Pheanstalk $pheanstalk
|
||||
* @param string $default
|
||||
* @param int $timeToRun
|
||||
* @param int $blockFor
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Pheanstalk $pheanstalk, $default, $timeToRun, $blockFor = 0)
|
||||
{
|
||||
$this->default = $default;
|
||||
$this->blockFor = $blockFor;
|
||||
$this->timeToRun = $timeToRun;
|
||||
$this->pheanstalk = $pheanstalk;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the size of the queue.
|
||||
*
|
||||
* @param string|null $queue
|
||||
* @return int
|
||||
*/
|
||||
public function size($queue = null)
|
||||
{
|
||||
$queue = $this->getQueue($queue);
|
||||
|
||||
return (int) $this->pheanstalk->statsTube($queue)->current_jobs_ready;
|
||||
}
|
||||
|
||||
/**
|
||||
* Push a new job onto the queue.
|
||||
*
|
||||
* @param string $job
|
||||
* @param mixed $data
|
||||
* @param string|null $queue
|
||||
* @return mixed
|
||||
*/
|
||||
public function push($job, $data = '', $queue = null)
|
||||
{
|
||||
return $this->pushRaw($this->createPayload($job, $this->getQueue($queue), $data), $queue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Push a raw payload onto the queue.
|
||||
*
|
||||
* @param string $payload
|
||||
* @param string|null $queue
|
||||
* @param array $options
|
||||
* @return mixed
|
||||
*/
|
||||
public function pushRaw($payload, $queue = null, array $options = [])
|
||||
{
|
||||
return $this->pheanstalk->useTube($this->getQueue($queue))->put(
|
||||
$payload, Pheanstalk::DEFAULT_PRIORITY, Pheanstalk::DEFAULT_DELAY, $this->timeToRun
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Push a new job onto the queue after a delay.
|
||||
*
|
||||
* @param \DateTimeInterface|\DateInterval|int $delay
|
||||
* @param string $job
|
||||
* @param mixed $data
|
||||
* @param string|null $queue
|
||||
* @return mixed
|
||||
*/
|
||||
public function later($delay, $job, $data = '', $queue = null)
|
||||
{
|
||||
$pheanstalk = $this->pheanstalk->useTube($this->getQueue($queue));
|
||||
|
||||
return $pheanstalk->put(
|
||||
$this->createPayload($job, $this->getQueue($queue), $data),
|
||||
Pheanstalk::DEFAULT_PRIORITY,
|
||||
$this->secondsUntil($delay),
|
||||
$this->timeToRun
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pop the next job off of the queue.
|
||||
*
|
||||
* @param string|null $queue
|
||||
* @return \Illuminate\Contracts\Queue\Job|null
|
||||
*/
|
||||
public function pop($queue = null)
|
||||
{
|
||||
$queue = $this->getQueue($queue);
|
||||
|
||||
$job = $this->pheanstalk->watchOnly($queue)->reserveWithTimeout($this->blockFor);
|
||||
|
||||
if ($job instanceof PheanstalkJob) {
|
||||
return new BeanstalkdJob(
|
||||
$this->container, $this->pheanstalk, $job, $this->connectionName, $queue
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a message from the Beanstalk queue.
|
||||
*
|
||||
* @param string $queue
|
||||
* @param string|int $id
|
||||
* @return void
|
||||
*/
|
||||
public function deleteMessage($queue, $id)
|
||||
{
|
||||
$queue = $this->getQueue($queue);
|
||||
|
||||
$this->pheanstalk->useTube($queue)->delete(new PheanstalkJob($id, ''));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the queue or return the default.
|
||||
*
|
||||
* @param string|null $queue
|
||||
* @return string
|
||||
*/
|
||||
public function getQueue($queue)
|
||||
{
|
||||
return $queue ?: $this->default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying Pheanstalk instance.
|
||||
*
|
||||
* @return \Pheanstalk\Pheanstalk
|
||||
*/
|
||||
public function getPheanstalk()
|
||||
{
|
||||
return $this->pheanstalk;
|
||||
}
|
||||
}
|
||||
74
vendor/laravel/framework/src/Illuminate/Queue/CallQueuedClosure.php
vendored
Normal file
74
vendor/laravel/framework/src/Illuminate/Queue/CallQueuedClosure.php
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Queue;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Container\Container;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use ReflectionFunction;
|
||||
|
||||
class CallQueuedClosure implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
/**
|
||||
* The serializable Closure instance.
|
||||
*
|
||||
* @var \Illuminate\Queue\SerializableClosure
|
||||
*/
|
||||
public $closure;
|
||||
|
||||
/**
|
||||
* Indicate if the job should be deleted when models are missing.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $deleteWhenMissingModels = true;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param \Illuminate\Queue\SerializableClosure $closure
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(SerializableClosure $closure)
|
||||
{
|
||||
$this->closure = $closure;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param \Closure $job
|
||||
* @return self
|
||||
*/
|
||||
public static function create(Closure $job)
|
||||
{
|
||||
return new self(new SerializableClosure($job));
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Container\Container $container
|
||||
* @return void
|
||||
*/
|
||||
public function handle(Container $container)
|
||||
{
|
||||
$container->call($this->closure->getClosure());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the display name for the queued job.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function displayName()
|
||||
{
|
||||
$reflection = new ReflectionFunction($this->closure->getClosure());
|
||||
|
||||
return 'Closure ('.basename($reflection->getFileName()).':'.$reflection->getStartLine().')';
|
||||
}
|
||||
}
|
||||
177
vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php
vendored
Normal file
177
vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php
vendored
Normal file
@@ -0,0 +1,177 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Queue;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Contracts\Bus\Dispatcher;
|
||||
use Illuminate\Contracts\Container\Container;
|
||||
use Illuminate\Contracts\Queue\Job;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Pipeline\Pipeline;
|
||||
use ReflectionClass;
|
||||
|
||||
class CallQueuedHandler
|
||||
{
|
||||
/**
|
||||
* The bus dispatcher implementation.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Bus\Dispatcher
|
||||
*/
|
||||
protected $dispatcher;
|
||||
|
||||
/**
|
||||
* The container instance.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Container\Container
|
||||
*/
|
||||
protected $container;
|
||||
|
||||
/**
|
||||
* Create a new handler instance.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Bus\Dispatcher $dispatcher
|
||||
* @param \Illuminate\Contracts\Container\Container $container
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Dispatcher $dispatcher, Container $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
$this->dispatcher = $dispatcher;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the queued job.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Queue\Job $job
|
||||
* @param array $data
|
||||
* @return void
|
||||
*/
|
||||
public function call(Job $job, array $data)
|
||||
{
|
||||
try {
|
||||
$command = $this->setJobInstanceIfNecessary(
|
||||
$job, unserialize($data['command'])
|
||||
);
|
||||
} catch (ModelNotFoundException $e) {
|
||||
return $this->handleModelNotFound($job, $e);
|
||||
}
|
||||
|
||||
$this->dispatchThroughMiddleware($job, $command);
|
||||
|
||||
if (! $job->hasFailed() && ! $job->isReleased()) {
|
||||
$this->ensureNextJobInChainIsDispatched($command);
|
||||
}
|
||||
|
||||
if (! $job->isDeletedOrReleased()) {
|
||||
$job->delete();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch the given job / command through its specified middleware.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Queue\Job $job
|
||||
* @param mixed $command
|
||||
* @return mixed
|
||||
*/
|
||||
protected function dispatchThroughMiddleware(Job $job, $command)
|
||||
{
|
||||
return (new Pipeline($this->container))->send($command)
|
||||
->through(array_merge(method_exists($command, 'middleware') ? $command->middleware() : [], $command->middleware ?? []))
|
||||
->then(function ($command) use ($job) {
|
||||
return $this->dispatcher->dispatchNow(
|
||||
$command, $this->resolveHandler($job, $command)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the handler for the given command.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Queue\Job $job
|
||||
* @param mixed $command
|
||||
* @return mixed
|
||||
*/
|
||||
protected function resolveHandler($job, $command)
|
||||
{
|
||||
$handler = $this->dispatcher->getCommandHandler($command) ?: null;
|
||||
|
||||
if ($handler) {
|
||||
$this->setJobInstanceIfNecessary($job, $handler);
|
||||
}
|
||||
|
||||
return $handler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the job instance of the given class if necessary.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Queue\Job $job
|
||||
* @param mixed $instance
|
||||
* @return mixed
|
||||
*/
|
||||
protected function setJobInstanceIfNecessary(Job $job, $instance)
|
||||
{
|
||||
if (in_array(InteractsWithQueue::class, class_uses_recursive($instance))) {
|
||||
$instance->setJob($job);
|
||||
}
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure the next job in the chain is dispatched if applicable.
|
||||
*
|
||||
* @param mixed $command
|
||||
* @return void
|
||||
*/
|
||||
protected function ensureNextJobInChainIsDispatched($command)
|
||||
{
|
||||
if (method_exists($command, 'dispatchNextJobInChain')) {
|
||||
$command->dispatchNextJobInChain();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle a model not found exception.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Queue\Job $job
|
||||
* @param \Throwable $e
|
||||
* @return void
|
||||
*/
|
||||
protected function handleModelNotFound(Job $job, $e)
|
||||
{
|
||||
$class = $job->resolveName();
|
||||
|
||||
try {
|
||||
$shouldDelete = (new ReflectionClass($class))
|
||||
->getDefaultProperties()['deleteWhenMissingModels'] ?? false;
|
||||
} catch (Exception $e) {
|
||||
$shouldDelete = false;
|
||||
}
|
||||
|
||||
if ($shouldDelete) {
|
||||
return $job->delete();
|
||||
}
|
||||
|
||||
return $job->fail($e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call the failed method on the job instance.
|
||||
*
|
||||
* The exception that caused the failure will be passed.
|
||||
*
|
||||
* @param array $data
|
||||
* @param \Throwable $e
|
||||
* @return void
|
||||
*/
|
||||
public function failed(array $data, $e)
|
||||
{
|
||||
$command = unserialize($data['command']);
|
||||
|
||||
if (method_exists($command, 'failed')) {
|
||||
$command->failed($e);
|
||||
}
|
||||
}
|
||||
}
|
||||
187
vendor/laravel/framework/src/Illuminate/Queue/Capsule/Manager.php
vendored
Normal file
187
vendor/laravel/framework/src/Illuminate/Queue/Capsule/Manager.php
vendored
Normal file
@@ -0,0 +1,187 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Queue\Capsule;
|
||||
|
||||
use Illuminate\Container\Container;
|
||||
use Illuminate\Queue\QueueManager;
|
||||
use Illuminate\Queue\QueueServiceProvider;
|
||||
use Illuminate\Support\Traits\CapsuleManagerTrait;
|
||||
|
||||
/**
|
||||
* @mixin \Illuminate\Queue\QueueManager
|
||||
* @mixin \Illuminate\Contracts\Queue\Queue
|
||||
*/
|
||||
class Manager
|
||||
{
|
||||
use CapsuleManagerTrait;
|
||||
|
||||
/**
|
||||
* The queue manager instance.
|
||||
*
|
||||
* @var \Illuminate\Queue\QueueManager
|
||||
*/
|
||||
protected $manager;
|
||||
|
||||
/**
|
||||
* Create a new queue capsule manager.
|
||||
*
|
||||
* @param \Illuminate\Container\Container|null $container
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Container $container = null)
|
||||
{
|
||||
$this->setupContainer($container ?: new Container);
|
||||
|
||||
// Once we have the container setup, we will setup the default configuration
|
||||
// options in the container "config" bindings. This just makes this queue
|
||||
// manager behave correctly since all the correct binding are in place.
|
||||
$this->setupDefaultConfiguration();
|
||||
|
||||
$this->setupManager();
|
||||
|
||||
$this->registerConnectors();
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup the default queue configuration options.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setupDefaultConfiguration()
|
||||
{
|
||||
$this->container['config']['queue.default'] = 'default';
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the queue manager instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setupManager()
|
||||
{
|
||||
$this->manager = new QueueManager($this->container);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the default connectors that the component ships with.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function registerConnectors()
|
||||
{
|
||||
$provider = new QueueServiceProvider($this->container);
|
||||
|
||||
$provider->registerConnectors($this->manager);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a connection instance from the global manager.
|
||||
*
|
||||
* @param string|null $connection
|
||||
* @return \Illuminate\Contracts\Queue\Queue
|
||||
*/
|
||||
public static function connection($connection = null)
|
||||
{
|
||||
return static::$instance->getConnection($connection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Push a new job onto the queue.
|
||||
*
|
||||
* @param string $job
|
||||
* @param mixed $data
|
||||
* @param string|null $queue
|
||||
* @param string|null $connection
|
||||
* @return mixed
|
||||
*/
|
||||
public static function push($job, $data = '', $queue = null, $connection = null)
|
||||
{
|
||||
return static::$instance->connection($connection)->push($job, $data, $queue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Push a new an array of jobs onto the queue.
|
||||
*
|
||||
* @param array $jobs
|
||||
* @param mixed $data
|
||||
* @param string|null $queue
|
||||
* @param string|null $connection
|
||||
* @return mixed
|
||||
*/
|
||||
public static function bulk($jobs, $data = '', $queue = null, $connection = null)
|
||||
{
|
||||
return static::$instance->connection($connection)->bulk($jobs, $data, $queue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Push a new job onto the queue after a delay.
|
||||
*
|
||||
* @param \DateTimeInterface|\DateInterval|int $delay
|
||||
* @param string $job
|
||||
* @param mixed $data
|
||||
* @param string|null $queue
|
||||
* @param string|null $connection
|
||||
* @return mixed
|
||||
*/
|
||||
public static function later($delay, $job, $data = '', $queue = null, $connection = null)
|
||||
{
|
||||
return static::$instance->connection($connection)->later($delay, $job, $data, $queue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a registered connection instance.
|
||||
*
|
||||
* @param string|null $name
|
||||
* @return \Illuminate\Contracts\Queue\Queue
|
||||
*/
|
||||
public function getConnection($name = null)
|
||||
{
|
||||
return $this->manager->connection($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a connection with the manager.
|
||||
*
|
||||
* @param array $config
|
||||
* @param string $name
|
||||
* @return void
|
||||
*/
|
||||
public function addConnection(array $config, $name = 'default')
|
||||
{
|
||||
$this->container['config']["queue.connections.{$name}"] = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the queue manager instance.
|
||||
*
|
||||
* @return \Illuminate\Queue\QueueManager
|
||||
*/
|
||||
public function getQueueManager()
|
||||
{
|
||||
return $this->manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pass dynamic instance methods to the manager.
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call($method, $parameters)
|
||||
{
|
||||
return $this->manager->$method(...$parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamically pass methods to the default connection.
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
* @return mixed
|
||||
*/
|
||||
public static function __callStatic($method, $parameters)
|
||||
{
|
||||
return static::connection()->$method(...$parameters);
|
||||
}
|
||||
}
|
||||
41
vendor/laravel/framework/src/Illuminate/Queue/Connectors/BeanstalkdConnector.php
vendored
Executable file
41
vendor/laravel/framework/src/Illuminate/Queue/Connectors/BeanstalkdConnector.php
vendored
Executable file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Queue\Connectors;
|
||||
|
||||
use Illuminate\Queue\BeanstalkdQueue;
|
||||
use Pheanstalk\Connection;
|
||||
use Pheanstalk\Pheanstalk;
|
||||
|
||||
class BeanstalkdConnector implements ConnectorInterface
|
||||
{
|
||||
/**
|
||||
* Establish a queue connection.
|
||||
*
|
||||
* @param array $config
|
||||
* @return \Illuminate\Contracts\Queue\Queue
|
||||
*/
|
||||
public function connect(array $config)
|
||||
{
|
||||
return new BeanstalkdQueue(
|
||||
$this->pheanstalk($config),
|
||||
$config['queue'],
|
||||
$config['retry_after'] ?? Pheanstalk::DEFAULT_TTR,
|
||||
$config['block_for'] ?? 0
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Pheanstalk instance.
|
||||
*
|
||||
* @param array $config
|
||||
* @return \Pheanstalk\Pheanstalk
|
||||
*/
|
||||
protected function pheanstalk(array $config)
|
||||
{
|
||||
return Pheanstalk::create(
|
||||
$config['host'],
|
||||
$config['port'] ?? Pheanstalk::DEFAULT_PORT,
|
||||
$config['timeout'] ?? Connection::DEFAULT_CONNECT_TIMEOUT
|
||||
);
|
||||
}
|
||||
}
|
||||
14
vendor/laravel/framework/src/Illuminate/Queue/Connectors/ConnectorInterface.php
vendored
Executable file
14
vendor/laravel/framework/src/Illuminate/Queue/Connectors/ConnectorInterface.php
vendored
Executable file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Queue\Connectors;
|
||||
|
||||
interface ConnectorInterface
|
||||
{
|
||||
/**
|
||||
* Establish a queue connection.
|
||||
*
|
||||
* @param array $config
|
||||
* @return \Illuminate\Contracts\Queue\Queue
|
||||
*/
|
||||
public function connect(array $config);
|
||||
}
|
||||
43
vendor/laravel/framework/src/Illuminate/Queue/Connectors/DatabaseConnector.php
vendored
Normal file
43
vendor/laravel/framework/src/Illuminate/Queue/Connectors/DatabaseConnector.php
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Queue\Connectors;
|
||||
|
||||
use Illuminate\Database\ConnectionResolverInterface;
|
||||
use Illuminate\Queue\DatabaseQueue;
|
||||
|
||||
class DatabaseConnector implements ConnectorInterface
|
||||
{
|
||||
/**
|
||||
* Database connections.
|
||||
*
|
||||
* @var \Illuminate\Database\ConnectionResolverInterface
|
||||
*/
|
||||
protected $connections;
|
||||
|
||||
/**
|
||||
* Create a new connector instance.
|
||||
*
|
||||
* @param \Illuminate\Database\ConnectionResolverInterface $connections
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(ConnectionResolverInterface $connections)
|
||||
{
|
||||
$this->connections = $connections;
|
||||
}
|
||||
|
||||
/**
|
||||
* Establish a queue connection.
|
||||
*
|
||||
* @param array $config
|
||||
* @return \Illuminate\Contracts\Queue\Queue
|
||||
*/
|
||||
public function connect(array $config)
|
||||
{
|
||||
return new DatabaseQueue(
|
||||
$this->connections->connection($config['connection'] ?? null),
|
||||
$config['table'],
|
||||
$config['queue'],
|
||||
$config['retry_after'] ?? 60
|
||||
);
|
||||
}
|
||||
}
|
||||
19
vendor/laravel/framework/src/Illuminate/Queue/Connectors/NullConnector.php
vendored
Normal file
19
vendor/laravel/framework/src/Illuminate/Queue/Connectors/NullConnector.php
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Queue\Connectors;
|
||||
|
||||
use Illuminate\Queue\NullQueue;
|
||||
|
||||
class NullConnector implements ConnectorInterface
|
||||
{
|
||||
/**
|
||||
* Establish a queue connection.
|
||||
*
|
||||
* @param array $config
|
||||
* @return \Illuminate\Contracts\Queue\Queue
|
||||
*/
|
||||
public function connect(array $config)
|
||||
{
|
||||
return new NullQueue;
|
||||
}
|
||||
}
|
||||
52
vendor/laravel/framework/src/Illuminate/Queue/Connectors/RedisConnector.php
vendored
Normal file
52
vendor/laravel/framework/src/Illuminate/Queue/Connectors/RedisConnector.php
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Queue\Connectors;
|
||||
|
||||
use Illuminate\Contracts\Redis\Factory as Redis;
|
||||
use Illuminate\Queue\RedisQueue;
|
||||
|
||||
class RedisConnector implements ConnectorInterface
|
||||
{
|
||||
/**
|
||||
* The Redis database instance.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Redis\Factory
|
||||
*/
|
||||
protected $redis;
|
||||
|
||||
/**
|
||||
* The connection name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $connection;
|
||||
|
||||
/**
|
||||
* Create a new Redis queue connector instance.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Redis\Factory $redis
|
||||
* @param string|null $connection
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Redis $redis, $connection = null)
|
||||
{
|
||||
$this->redis = $redis;
|
||||
$this->connection = $connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Establish a queue connection.
|
||||
*
|
||||
* @param array $config
|
||||
* @return \Illuminate\Contracts\Queue\Queue
|
||||
*/
|
||||
public function connect(array $config)
|
||||
{
|
||||
return new RedisQueue(
|
||||
$this->redis, $config['queue'],
|
||||
$config['connection'] ?? $this->connection,
|
||||
$config['retry_after'] ?? 60,
|
||||
$config['block_for'] ?? null
|
||||
);
|
||||
}
|
||||
}
|
||||
46
vendor/laravel/framework/src/Illuminate/Queue/Connectors/SqsConnector.php
vendored
Executable file
46
vendor/laravel/framework/src/Illuminate/Queue/Connectors/SqsConnector.php
vendored
Executable file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Queue\Connectors;
|
||||
|
||||
use Aws\Sqs\SqsClient;
|
||||
use Illuminate\Queue\SqsQueue;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
class SqsConnector implements ConnectorInterface
|
||||
{
|
||||
/**
|
||||
* Establish a queue connection.
|
||||
*
|
||||
* @param array $config
|
||||
* @return \Illuminate\Contracts\Queue\Queue
|
||||
*/
|
||||
public function connect(array $config)
|
||||
{
|
||||
$config = $this->getDefaultConfiguration($config);
|
||||
|
||||
if (! empty($config['key']) && ! empty($config['secret'])) {
|
||||
$config['credentials'] = Arr::only($config, ['key', 'secret', 'token']);
|
||||
}
|
||||
|
||||
return new SqsQueue(
|
||||
new SqsClient($config), $config['queue'], $config['prefix'] ?? '', $config['suffix'] ?? ''
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default configuration for SQS.
|
||||
*
|
||||
* @param array $config
|
||||
* @return array
|
||||
*/
|
||||
protected function getDefaultConfiguration(array $config)
|
||||
{
|
||||
return array_merge([
|
||||
'version' => 'latest',
|
||||
'http' => [
|
||||
'timeout' => 60,
|
||||
'connect_timeout' => 60,
|
||||
],
|
||||
], $config);
|
||||
}
|
||||
}
|
||||
19
vendor/laravel/framework/src/Illuminate/Queue/Connectors/SyncConnector.php
vendored
Executable file
19
vendor/laravel/framework/src/Illuminate/Queue/Connectors/SyncConnector.php
vendored
Executable file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Queue\Connectors;
|
||||
|
||||
use Illuminate\Queue\SyncQueue;
|
||||
|
||||
class SyncConnector implements ConnectorInterface
|
||||
{
|
||||
/**
|
||||
* Establish a queue connection.
|
||||
*
|
||||
* @param array $config
|
||||
* @return \Illuminate\Contracts\Queue\Queue
|
||||
*/
|
||||
public function connect(array $config)
|
||||
{
|
||||
return new SyncQueue;
|
||||
}
|
||||
}
|
||||
102
vendor/laravel/framework/src/Illuminate/Queue/Console/FailedTableCommand.php
vendored
Normal file
102
vendor/laravel/framework/src/Illuminate/Queue/Console/FailedTableCommand.php
vendored
Normal file
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Queue\Console;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
use Illuminate\Support\Composer;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class FailedTableCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'queue:failed-table';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Create a migration for the failed queue jobs database table';
|
||||
|
||||
/**
|
||||
* The filesystem instance.
|
||||
*
|
||||
* @var \Illuminate\Filesystem\Filesystem
|
||||
*/
|
||||
protected $files;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Support\Composer
|
||||
*/
|
||||
protected $composer;
|
||||
|
||||
/**
|
||||
* Create a new failed queue jobs table command instance.
|
||||
*
|
||||
* @param \Illuminate\Filesystem\Filesystem $files
|
||||
* @param \Illuminate\Support\Composer $composer
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Filesystem $files, Composer $composer)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->files = $files;
|
||||
$this->composer = $composer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$table = $this->laravel['config']['queue.failed.table'];
|
||||
|
||||
$this->replaceMigration(
|
||||
$this->createBaseMigration($table), $table, Str::studly($table)
|
||||
);
|
||||
|
||||
$this->info('Migration created successfully!');
|
||||
|
||||
$this->composer->dumpAutoloads();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a base migration file for the table.
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function createBaseMigration($table = 'failed_jobs')
|
||||
{
|
||||
return $this->laravel['migration.creator']->create(
|
||||
'create_'.$table.'_table', $this->laravel->databasePath().'/migrations'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace the generated migration with the failed job table stub.
|
||||
*
|
||||
* @param string $path
|
||||
* @param string $table
|
||||
* @param string $tableClassName
|
||||
* @return void
|
||||
*/
|
||||
protected function replaceMigration($path, $table, $tableClassName)
|
||||
{
|
||||
$stub = str_replace(
|
||||
['{{table}}', '{{tableClassName}}'],
|
||||
[$table, $tableClassName],
|
||||
$this->files->get(__DIR__.'/stubs/failed_jobs.stub')
|
||||
);
|
||||
|
||||
$this->files->put($path, $stub);
|
||||
}
|
||||
}
|
||||
34
vendor/laravel/framework/src/Illuminate/Queue/Console/FlushFailedCommand.php
vendored
Normal file
34
vendor/laravel/framework/src/Illuminate/Queue/Console/FlushFailedCommand.php
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Queue\Console;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class FlushFailedCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'queue:flush';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Flush all of the failed queue jobs';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->laravel['queue.failer']->flush();
|
||||
|
||||
$this->info('All failed jobs deleted successfully!');
|
||||
}
|
||||
}
|
||||
36
vendor/laravel/framework/src/Illuminate/Queue/Console/ForgetFailedCommand.php
vendored
Normal file
36
vendor/laravel/framework/src/Illuminate/Queue/Console/ForgetFailedCommand.php
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Queue\Console;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class ForgetFailedCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The console command signature.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'queue:forget {id : The ID of the failed job}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Delete a failed queue job';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
if ($this->laravel['queue.failer']->forget($this->argument('id'))) {
|
||||
$this->info('Failed job deleted successfully!');
|
||||
} else {
|
||||
$this->error('No failed job matches the given ID.');
|
||||
}
|
||||
}
|
||||
}
|
||||
114
vendor/laravel/framework/src/Illuminate/Queue/Console/ListFailedCommand.php
vendored
Normal file
114
vendor/laravel/framework/src/Illuminate/Queue/Console/ListFailedCommand.php
vendored
Normal file
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Queue\Console;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
class ListFailedCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'queue:failed';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'List all of the failed queue jobs';
|
||||
|
||||
/**
|
||||
* The table headers for the command.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $headers = ['ID', 'Connection', 'Queue', 'Class', 'Failed At'];
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
if (count($jobs = $this->getFailedJobs()) === 0) {
|
||||
return $this->info('No failed jobs!');
|
||||
}
|
||||
|
||||
$this->displayFailedJobs($jobs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the failed jobs into a displayable format.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getFailedJobs()
|
||||
{
|
||||
$failed = $this->laravel['queue.failer']->all();
|
||||
|
||||
return collect($failed)->map(function ($failed) {
|
||||
return $this->parseFailedJob((array) $failed);
|
||||
})->filter()->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the failed job row.
|
||||
*
|
||||
* @param array $failed
|
||||
* @return array
|
||||
*/
|
||||
protected function parseFailedJob(array $failed)
|
||||
{
|
||||
$row = array_values(Arr::except($failed, ['payload', 'exception']));
|
||||
|
||||
array_splice($row, 3, 0, $this->extractJobName($failed['payload']));
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract the failed job name from payload.
|
||||
*
|
||||
* @param string $payload
|
||||
* @return string|null
|
||||
*/
|
||||
private function extractJobName($payload)
|
||||
{
|
||||
$payload = json_decode($payload, true);
|
||||
|
||||
if ($payload && (! isset($payload['data']['command']))) {
|
||||
return $payload['job'] ?? null;
|
||||
} elseif ($payload && isset($payload['data']['command'])) {
|
||||
return $this->matchJobName($payload);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Match the job name from the payload.
|
||||
*
|
||||
* @param array $payload
|
||||
* @return string|null
|
||||
*/
|
||||
protected function matchJobName($payload)
|
||||
{
|
||||
preg_match('/"([^"]+)"/', $payload['data']['command'], $matches);
|
||||
|
||||
return $matches[1] ?? $payload['job'] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the failed jobs in the console.
|
||||
*
|
||||
* @param array $jobs
|
||||
* @return void
|
||||
*/
|
||||
protected function displayFailedJobs(array $jobs)
|
||||
{
|
||||
$this->table($this->headers, $jobs);
|
||||
}
|
||||
}
|
||||
114
vendor/laravel/framework/src/Illuminate/Queue/Console/ListenCommand.php
vendored
Executable file
114
vendor/laravel/framework/src/Illuminate/Queue/Console/ListenCommand.php
vendored
Executable file
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Queue\Console;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Queue\Listener;
|
||||
use Illuminate\Queue\ListenerOptions;
|
||||
|
||||
class ListenCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'queue:listen
|
||||
{connection? : The name of connection}
|
||||
{--delay=0 : The number of seconds to delay failed jobs}
|
||||
{--force : Force the worker to run even in maintenance mode}
|
||||
{--memory=128 : The memory limit in megabytes}
|
||||
{--queue= : The queue to listen on}
|
||||
{--sleep=3 : Number of seconds to sleep when no job is available}
|
||||
{--timeout=60 : The number of seconds a child process can run}
|
||||
{--tries=1 : Number of times to attempt a job before logging it failed}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Listen to a given queue';
|
||||
|
||||
/**
|
||||
* The queue listener instance.
|
||||
*
|
||||
* @var \Illuminate\Queue\Listener
|
||||
*/
|
||||
protected $listener;
|
||||
|
||||
/**
|
||||
* Create a new queue listen command.
|
||||
*
|
||||
* @param \Illuminate\Queue\Listener $listener
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Listener $listener)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->setOutputHandler($this->listener = $listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
// We need to get the right queue for the connection which is set in the queue
|
||||
// configuration file for the application. We will pull it based on the set
|
||||
// connection being run for the queue operation currently being executed.
|
||||
$queue = $this->getQueue(
|
||||
$connection = $this->input->getArgument('connection')
|
||||
);
|
||||
|
||||
$this->listener->listen(
|
||||
$connection, $queue, $this->gatherOptions()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the queue connection to listen on.
|
||||
*
|
||||
* @param string $connection
|
||||
* @return string
|
||||
*/
|
||||
protected function getQueue($connection)
|
||||
{
|
||||
$connection = $connection ?: $this->laravel['config']['queue.default'];
|
||||
|
||||
return $this->input->getOption('queue') ?: $this->laravel['config']->get(
|
||||
"queue.connections.{$connection}.queue", 'default'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the listener options for the command.
|
||||
*
|
||||
* @return \Illuminate\Queue\ListenerOptions
|
||||
*/
|
||||
protected function gatherOptions()
|
||||
{
|
||||
return new ListenerOptions(
|
||||
$this->option('env'), $this->option('delay'),
|
||||
$this->option('memory'), $this->option('timeout'),
|
||||
$this->option('sleep'), $this->option('tries'),
|
||||
$this->option('force')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the options on the queue listener.
|
||||
*
|
||||
* @param \Illuminate\Queue\Listener $listener
|
||||
* @return void
|
||||
*/
|
||||
protected function setOutputHandler(Listener $listener)
|
||||
{
|
||||
$listener->setOutputHandler(function ($type, $line) {
|
||||
$this->output->write($line);
|
||||
});
|
||||
}
|
||||
}
|
||||
58
vendor/laravel/framework/src/Illuminate/Queue/Console/RestartCommand.php
vendored
Normal file
58
vendor/laravel/framework/src/Illuminate/Queue/Console/RestartCommand.php
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Queue\Console;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Contracts\Cache\Repository as Cache;
|
||||
use Illuminate\Support\InteractsWithTime;
|
||||
|
||||
class RestartCommand extends Command
|
||||
{
|
||||
use InteractsWithTime;
|
||||
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'queue:restart';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Restart queue worker daemons after their current job';
|
||||
|
||||
/**
|
||||
* The cache store implementation.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Cache\Repository
|
||||
*/
|
||||
protected $cache;
|
||||
|
||||
/**
|
||||
* Create a new queue restart command.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Cache\Repository $cache
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Cache $cache)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->cache = $cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->cache->forever('illuminate:queue:restart', $this->currentTime());
|
||||
|
||||
$this->info('Broadcasting queue restart signal.');
|
||||
}
|
||||
}
|
||||
118
vendor/laravel/framework/src/Illuminate/Queue/Console/RetryCommand.php
vendored
Normal file
118
vendor/laravel/framework/src/Illuminate/Queue/Console/RetryCommand.php
vendored
Normal file
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Queue\Console;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
class RetryCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The console command signature.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'queue:retry
|
||||
{id?* : The ID of the failed job or "all" to retry all jobs}
|
||||
{--range=* : Range of job IDs (numeric) to be retried}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Retry a failed queue job';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
foreach ($this->getJobIds() as $id) {
|
||||
$job = $this->laravel['queue.failer']->find($id);
|
||||
|
||||
if (is_null($job)) {
|
||||
$this->error("Unable to find failed job with ID [{$id}].");
|
||||
} else {
|
||||
$this->retryJob($job);
|
||||
|
||||
$this->info("The failed job [{$id}] has been pushed back onto the queue!");
|
||||
|
||||
$this->laravel['queue.failer']->forget($id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the job IDs to be retried.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getJobIds()
|
||||
{
|
||||
$ids = (array) $this->argument('id');
|
||||
|
||||
if (count($ids) === 1 && $ids[0] === 'all') {
|
||||
return Arr::pluck($this->laravel['queue.failer']->all(), 'id');
|
||||
}
|
||||
|
||||
if ($ranges = (array) $this->option('range')) {
|
||||
$ids = array_merge($ids, $this->getJobIdsByRanges($ranges));
|
||||
}
|
||||
|
||||
return array_values(array_filter(array_unique($ids)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the job IDs ranges, if applicable.
|
||||
*
|
||||
* @param array $ranges
|
||||
* @return array
|
||||
*/
|
||||
protected function getJobIdsByRanges(array $ranges)
|
||||
{
|
||||
$ids = [];
|
||||
|
||||
foreach ($ranges as $range) {
|
||||
if (preg_match('/^[0-9]+\-[0-9]+$/', $range)) {
|
||||
$ids = array_merge($ids, range(...explode('-', $range)));
|
||||
}
|
||||
}
|
||||
|
||||
return $ids;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retry the queue job.
|
||||
*
|
||||
* @param \stdClass $job
|
||||
* @return void
|
||||
*/
|
||||
protected function retryJob($job)
|
||||
{
|
||||
$this->laravel['queue']->connection($job->connection)->pushRaw(
|
||||
$this->resetAttempts($job->payload), $job->queue
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the payload attempts.
|
||||
*
|
||||
* Applicable to Redis jobs which store attempts in their payload.
|
||||
*
|
||||
* @param string $payload
|
||||
* @return string
|
||||
*/
|
||||
protected function resetAttempts($payload)
|
||||
{
|
||||
$payload = json_decode($payload, true);
|
||||
|
||||
if (isset($payload['attempts'])) {
|
||||
$payload['attempts'] = 0;
|
||||
}
|
||||
|
||||
return json_encode($payload);
|
||||
}
|
||||
}
|
||||
102
vendor/laravel/framework/src/Illuminate/Queue/Console/TableCommand.php
vendored
Normal file
102
vendor/laravel/framework/src/Illuminate/Queue/Console/TableCommand.php
vendored
Normal file
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Queue\Console;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
use Illuminate\Support\Composer;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class TableCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'queue:table';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Create a migration for the queue jobs database table';
|
||||
|
||||
/**
|
||||
* The filesystem instance.
|
||||
*
|
||||
* @var \Illuminate\Filesystem\Filesystem
|
||||
*/
|
||||
protected $files;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Support\Composer
|
||||
*/
|
||||
protected $composer;
|
||||
|
||||
/**
|
||||
* Create a new queue job table command instance.
|
||||
*
|
||||
* @param \Illuminate\Filesystem\Filesystem $files
|
||||
* @param \Illuminate\Support\Composer $composer
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Filesystem $files, Composer $composer)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->files = $files;
|
||||
$this->composer = $composer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$table = $this->laravel['config']['queue.connections.database.table'];
|
||||
|
||||
$this->replaceMigration(
|
||||
$this->createBaseMigration($table), $table, Str::studly($table)
|
||||
);
|
||||
|
||||
$this->info('Migration created successfully!');
|
||||
|
||||
$this->composer->dumpAutoloads();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a base migration file for the table.
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function createBaseMigration($table = 'jobs')
|
||||
{
|
||||
return $this->laravel['migration.creator']->create(
|
||||
'create_'.$table.'_table', $this->laravel->databasePath().'/migrations'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace the generated migration with the job table stub.
|
||||
*
|
||||
* @param string $path
|
||||
* @param string $table
|
||||
* @param string $tableClassName
|
||||
* @return void
|
||||
*/
|
||||
protected function replaceMigration($path, $table, $tableClassName)
|
||||
{
|
||||
$stub = str_replace(
|
||||
['{{table}}', '{{tableClassName}}'],
|
||||
[$table, $tableClassName],
|
||||
$this->files->get(__DIR__.'/stubs/jobs.stub')
|
||||
);
|
||||
|
||||
$this->files->put($path, $stub);
|
||||
}
|
||||
}
|
||||
226
vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php
vendored
Normal file
226
vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php
vendored
Normal file
@@ -0,0 +1,226 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Queue\Console;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Contracts\Cache\Repository as Cache;
|
||||
use Illuminate\Contracts\Queue\Job;
|
||||
use Illuminate\Queue\Events\JobFailed;
|
||||
use Illuminate\Queue\Events\JobProcessed;
|
||||
use Illuminate\Queue\Events\JobProcessing;
|
||||
use Illuminate\Queue\Worker;
|
||||
use Illuminate\Queue\WorkerOptions;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
class WorkCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'queue:work
|
||||
{connection? : The name of the queue connection to work}
|
||||
{--queue= : The names of the queues to work}
|
||||
{--daemon : Run the worker in daemon mode (Deprecated)}
|
||||
{--once : Only process the next job on the queue}
|
||||
{--stop-when-empty : Stop when the queue is empty}
|
||||
{--delay=0 : The number of seconds to delay failed jobs}
|
||||
{--force : Force the worker to run even in maintenance mode}
|
||||
{--memory=128 : The memory limit in megabytes}
|
||||
{--sleep=3 : Number of seconds to sleep when no job is available}
|
||||
{--timeout=60 : The number of seconds a child process can run}
|
||||
{--tries=1 : Number of times to attempt a job before logging it failed}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Start processing jobs on the queue as a daemon';
|
||||
|
||||
/**
|
||||
* The queue worker instance.
|
||||
*
|
||||
* @var \Illuminate\Queue\Worker
|
||||
*/
|
||||
protected $worker;
|
||||
|
||||
/**
|
||||
* The cache store implementation.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Cache\Repository
|
||||
*/
|
||||
protected $cache;
|
||||
|
||||
/**
|
||||
* Create a new queue work command.
|
||||
*
|
||||
* @param \Illuminate\Queue\Worker $worker
|
||||
* @param \Illuminate\Contracts\Cache\Repository $cache
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Worker $worker, Cache $cache)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->cache = $cache;
|
||||
$this->worker = $worker;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
if ($this->downForMaintenance() && $this->option('once')) {
|
||||
return $this->worker->sleep($this->option('sleep'));
|
||||
}
|
||||
|
||||
// We'll listen to the processed and failed events so we can write information
|
||||
// to the console as jobs are processed, which will let the developer watch
|
||||
// which jobs are coming through a queue and be informed on its progress.
|
||||
$this->listenForEvents();
|
||||
|
||||
$connection = $this->argument('connection')
|
||||
?: $this->laravel['config']['queue.default'];
|
||||
|
||||
// We need to get the right queue for the connection which is set in the queue
|
||||
// configuration file for the application. We will pull it based on the set
|
||||
// connection being run for the queue operation currently being executed.
|
||||
$queue = $this->getQueue($connection);
|
||||
|
||||
$this->runWorker(
|
||||
$connection, $queue
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the worker instance.
|
||||
*
|
||||
* @param string $connection
|
||||
* @param string $queue
|
||||
* @return array
|
||||
*/
|
||||
protected function runWorker($connection, $queue)
|
||||
{
|
||||
$this->worker->setCache($this->cache);
|
||||
|
||||
return $this->worker->{$this->option('once') ? 'runNextJob' : 'daemon'}(
|
||||
$connection, $queue, $this->gatherWorkerOptions()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gather all of the queue worker options as a single object.
|
||||
*
|
||||
* @return \Illuminate\Queue\WorkerOptions
|
||||
*/
|
||||
protected function gatherWorkerOptions()
|
||||
{
|
||||
return new WorkerOptions(
|
||||
$this->option('delay'), $this->option('memory'),
|
||||
$this->option('timeout'), $this->option('sleep'),
|
||||
$this->option('tries'), $this->option('force'),
|
||||
$this->option('stop-when-empty')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Listen for the queue events in order to update the console output.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function listenForEvents()
|
||||
{
|
||||
$this->laravel['events']->listen(JobProcessing::class, function ($event) {
|
||||
$this->writeOutput($event->job, 'starting');
|
||||
});
|
||||
|
||||
$this->laravel['events']->listen(JobProcessed::class, function ($event) {
|
||||
$this->writeOutput($event->job, 'success');
|
||||
});
|
||||
|
||||
$this->laravel['events']->listen(JobFailed::class, function ($event) {
|
||||
$this->writeOutput($event->job, 'failed');
|
||||
|
||||
$this->logFailedJob($event);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the status output for the queue worker.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Queue\Job $job
|
||||
* @param string $status
|
||||
* @return void
|
||||
*/
|
||||
protected function writeOutput(Job $job, $status)
|
||||
{
|
||||
switch ($status) {
|
||||
case 'starting':
|
||||
return $this->writeStatus($job, 'Processing', 'comment');
|
||||
case 'success':
|
||||
return $this->writeStatus($job, 'Processed', 'info');
|
||||
case 'failed':
|
||||
return $this->writeStatus($job, 'Failed', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the status output for the queue worker.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Queue\Job $job
|
||||
* @param string $status
|
||||
* @param string $type
|
||||
* @return void
|
||||
*/
|
||||
protected function writeStatus(Job $job, $status, $type)
|
||||
{
|
||||
$this->output->writeln(sprintf(
|
||||
"<{$type}>[%s][%s] %s</{$type}> %s",
|
||||
Carbon::now()->format('Y-m-d H:i:s'),
|
||||
$job->getJobId(),
|
||||
str_pad("{$status}:", 11), $job->resolveName()
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a failed job event.
|
||||
*
|
||||
* @param \Illuminate\Queue\Events\JobFailed $event
|
||||
* @return void
|
||||
*/
|
||||
protected function logFailedJob(JobFailed $event)
|
||||
{
|
||||
$this->laravel['queue.failer']->log(
|
||||
$event->connectionName, $event->job->getQueue(),
|
||||
$event->job->getRawBody(), $event->exception
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the queue name for the worker.
|
||||
*
|
||||
* @param string $connection
|
||||
* @return string
|
||||
*/
|
||||
protected function getQueue($connection)
|
||||
{
|
||||
return $this->option('queue') ?: $this->laravel['config']->get(
|
||||
"queue.connections.{$connection}.queue", 'default'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the worker should run in maintenance mode.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function downForMaintenance()
|
||||
{
|
||||
return $this->option('force') ? false : $this->laravel->isDownForMaintenance();
|
||||
}
|
||||
}
|
||||
35
vendor/laravel/framework/src/Illuminate/Queue/Console/stubs/failed_jobs.stub
vendored
Normal file
35
vendor/laravel/framework/src/Illuminate/Queue/Console/stubs/failed_jobs.stub
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class Create{{tableClassName}}Table extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('{{table}}', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->text('connection');
|
||||
$table->text('queue');
|
||||
$table->longText('payload');
|
||||
$table->longText('exception');
|
||||
$table->timestamp('failed_at')->useCurrent();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('{{table}}');
|
||||
}
|
||||
}
|
||||
36
vendor/laravel/framework/src/Illuminate/Queue/Console/stubs/jobs.stub
vendored
Normal file
36
vendor/laravel/framework/src/Illuminate/Queue/Console/stubs/jobs.stub
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class Create{{tableClassName}}Table extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('{{table}}', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->string('queue')->index();
|
||||
$table->longText('payload');
|
||||
$table->unsignedTinyInteger('attempts');
|
||||
$table->unsignedInteger('reserved_at')->nullable();
|
||||
$table->unsignedInteger('available_at');
|
||||
$table->unsignedInteger('created_at');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('{{table}}');
|
||||
}
|
||||
}
|
||||
344
vendor/laravel/framework/src/Illuminate/Queue/DatabaseQueue.php
vendored
Normal file
344
vendor/laravel/framework/src/Illuminate/Queue/DatabaseQueue.php
vendored
Normal file
@@ -0,0 +1,344 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Queue;
|
||||
|
||||
use Illuminate\Contracts\Queue\Queue as QueueContract;
|
||||
use Illuminate\Database\Connection;
|
||||
use Illuminate\Queue\Jobs\DatabaseJob;
|
||||
use Illuminate\Queue\Jobs\DatabaseJobRecord;
|
||||
use Illuminate\Support\Carbon;
|
||||
use PDO;
|
||||
|
||||
class DatabaseQueue extends Queue implements QueueContract
|
||||
{
|
||||
/**
|
||||
* The database connection instance.
|
||||
*
|
||||
* @var \Illuminate\Database\Connection
|
||||
*/
|
||||
protected $database;
|
||||
|
||||
/**
|
||||
* The database table that holds the jobs.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table;
|
||||
|
||||
/**
|
||||
* The name of the default queue.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $default;
|
||||
|
||||
/**
|
||||
* The expiration time of a job.
|
||||
*
|
||||
* @var int|null
|
||||
*/
|
||||
protected $retryAfter = 60;
|
||||
|
||||
/**
|
||||
* Create a new database queue instance.
|
||||
*
|
||||
* @param \Illuminate\Database\Connection $database
|
||||
* @param string $table
|
||||
* @param string $default
|
||||
* @param int $retryAfter
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Connection $database, $table, $default = 'default', $retryAfter = 60)
|
||||
{
|
||||
$this->table = $table;
|
||||
$this->default = $default;
|
||||
$this->database = $database;
|
||||
$this->retryAfter = $retryAfter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the size of the queue.
|
||||
*
|
||||
* @param string|null $queue
|
||||
* @return int
|
||||
*/
|
||||
public function size($queue = null)
|
||||
{
|
||||
return $this->database->table($this->table)
|
||||
->where('queue', $this->getQueue($queue))
|
||||
->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* Push a new job onto the queue.
|
||||
*
|
||||
* @param string $job
|
||||
* @param mixed $data
|
||||
* @param string|null $queue
|
||||
* @return mixed
|
||||
*/
|
||||
public function push($job, $data = '', $queue = null)
|
||||
{
|
||||
return $this->pushToDatabase($queue, $this->createPayload(
|
||||
$job, $this->getQueue($queue), $data
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Push a raw payload onto the queue.
|
||||
*
|
||||
* @param string $payload
|
||||
* @param string|null $queue
|
||||
* @param array $options
|
||||
* @return mixed
|
||||
*/
|
||||
public function pushRaw($payload, $queue = null, array $options = [])
|
||||
{
|
||||
return $this->pushToDatabase($queue, $payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* Push a new job onto the queue after a delay.
|
||||
*
|
||||
* @param \DateTimeInterface|\DateInterval|int $delay
|
||||
* @param string $job
|
||||
* @param mixed $data
|
||||
* @param string|null $queue
|
||||
* @return void
|
||||
*/
|
||||
public function later($delay, $job, $data = '', $queue = null)
|
||||
{
|
||||
return $this->pushToDatabase($queue, $this->createPayload(
|
||||
$job, $this->getQueue($queue), $data
|
||||
), $delay);
|
||||
}
|
||||
|
||||
/**
|
||||
* Push an array of jobs onto the queue.
|
||||
*
|
||||
* @param array $jobs
|
||||
* @param mixed $data
|
||||
* @param string|null $queue
|
||||
* @return mixed
|
||||
*/
|
||||
public function bulk($jobs, $data = '', $queue = null)
|
||||
{
|
||||
$queue = $this->getQueue($queue);
|
||||
|
||||
$availableAt = $this->availableAt();
|
||||
|
||||
return $this->database->table($this->table)->insert(collect((array) $jobs)->map(
|
||||
function ($job) use ($queue, $data, $availableAt) {
|
||||
return $this->buildDatabaseRecord($queue, $this->createPayload($job, $this->getQueue($queue), $data), $availableAt);
|
||||
}
|
||||
)->all());
|
||||
}
|
||||
|
||||
/**
|
||||
* Release a reserved job back onto the queue.
|
||||
*
|
||||
* @param string $queue
|
||||
* @param \Illuminate\Queue\Jobs\DatabaseJobRecord $job
|
||||
* @param int $delay
|
||||
* @return mixed
|
||||
*/
|
||||
public function release($queue, $job, $delay)
|
||||
{
|
||||
return $this->pushToDatabase($queue, $job->payload, $delay, $job->attempts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Push a raw payload to the database with a given delay.
|
||||
*
|
||||
* @param string|null $queue
|
||||
* @param string $payload
|
||||
* @param \DateTimeInterface|\DateInterval|int $delay
|
||||
* @param int $attempts
|
||||
* @return mixed
|
||||
*/
|
||||
protected function pushToDatabase($queue, $payload, $delay = 0, $attempts = 0)
|
||||
{
|
||||
return $this->database->table($this->table)->insertGetId($this->buildDatabaseRecord(
|
||||
$this->getQueue($queue), $payload, $this->availableAt($delay), $attempts
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an array to insert for the given job.
|
||||
*
|
||||
* @param string|null $queue
|
||||
* @param string $payload
|
||||
* @param int $availableAt
|
||||
* @param int $attempts
|
||||
* @return array
|
||||
*/
|
||||
protected function buildDatabaseRecord($queue, $payload, $availableAt, $attempts = 0)
|
||||
{
|
||||
return [
|
||||
'queue' => $queue,
|
||||
'attempts' => $attempts,
|
||||
'reserved_at' => null,
|
||||
'available_at' => $availableAt,
|
||||
'created_at' => $this->currentTime(),
|
||||
'payload' => $payload,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Pop the next job off of the queue.
|
||||
*
|
||||
* @param string|null $queue
|
||||
* @return \Illuminate\Contracts\Queue\Job|null
|
||||
*
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function pop($queue = null)
|
||||
{
|
||||
$queue = $this->getQueue($queue);
|
||||
|
||||
return $this->database->transaction(function () use ($queue) {
|
||||
if ($job = $this->getNextAvailableJob($queue)) {
|
||||
return $this->marshalJob($queue, $job);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the next available job for the queue.
|
||||
*
|
||||
* @param string|null $queue
|
||||
* @return \Illuminate\Queue\Jobs\DatabaseJobRecord|null
|
||||
*/
|
||||
protected function getNextAvailableJob($queue)
|
||||
{
|
||||
$job = $this->database->table($this->table)
|
||||
->lock($this->getLockForPopping())
|
||||
->where('queue', $this->getQueue($queue))
|
||||
->where(function ($query) {
|
||||
$this->isAvailable($query);
|
||||
$this->isReservedButExpired($query);
|
||||
})
|
||||
->orderBy('id', 'asc')
|
||||
->first();
|
||||
|
||||
return $job ? new DatabaseJobRecord((object) $job) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the lock required for popping the next job.
|
||||
*
|
||||
* @return string|bool
|
||||
*/
|
||||
protected function getLockForPopping()
|
||||
{
|
||||
$databaseEngine = $this->database->getPdo()->getAttribute(PDO::ATTR_DRIVER_NAME);
|
||||
$databaseVersion = $this->database->getPdo()->getAttribute(PDO::ATTR_SERVER_VERSION);
|
||||
|
||||
if ($databaseEngine == 'mysql' && ! strpos($databaseVersion, 'MariaDB') && version_compare($databaseVersion, '8.0.1', '>=') ||
|
||||
$databaseEngine == 'pgsql' && version_compare($databaseVersion, '9.5', '>=')) {
|
||||
return 'FOR UPDATE SKIP LOCKED';
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify the query to check for available jobs.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @return void
|
||||
*/
|
||||
protected function isAvailable($query)
|
||||
{
|
||||
$query->where(function ($query) {
|
||||
$query->whereNull('reserved_at')
|
||||
->where('available_at', '<=', $this->currentTime());
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify the query to check for jobs that are reserved but have expired.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query
|
||||
* @return void
|
||||
*/
|
||||
protected function isReservedButExpired($query)
|
||||
{
|
||||
$expiration = Carbon::now()->subSeconds($this->retryAfter)->getTimestamp();
|
||||
|
||||
$query->orWhere(function ($query) use ($expiration) {
|
||||
$query->where('reserved_at', '<=', $expiration);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Marshal the reserved job into a DatabaseJob instance.
|
||||
*
|
||||
* @param string $queue
|
||||
* @param \Illuminate\Queue\Jobs\DatabaseJobRecord $job
|
||||
* @return \Illuminate\Queue\Jobs\DatabaseJob
|
||||
*/
|
||||
protected function marshalJob($queue, $job)
|
||||
{
|
||||
$job = $this->markJobAsReserved($job);
|
||||
|
||||
return new DatabaseJob(
|
||||
$this->container, $this, $job, $this->connectionName, $queue
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark the given job ID as reserved.
|
||||
*
|
||||
* @param \Illuminate\Queue\Jobs\DatabaseJobRecord $job
|
||||
* @return \Illuminate\Queue\Jobs\DatabaseJobRecord
|
||||
*/
|
||||
protected function markJobAsReserved($job)
|
||||
{
|
||||
$this->database->table($this->table)->where('id', $job->id)->update([
|
||||
'reserved_at' => $job->touch(),
|
||||
'attempts' => $job->increment(),
|
||||
]);
|
||||
|
||||
return $job;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a reserved job from the queue.
|
||||
*
|
||||
* @param string $queue
|
||||
* @param string $id
|
||||
* @return void
|
||||
*
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function deleteReserved($queue, $id)
|
||||
{
|
||||
$this->database->transaction(function () use ($id) {
|
||||
if ($this->database->table($this->table)->lockForUpdate()->find($id)) {
|
||||
$this->database->table($this->table)->where('id', $id)->delete();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the queue or return the default.
|
||||
*
|
||||
* @param string|null $queue
|
||||
* @return string
|
||||
*/
|
||||
public function getQueue($queue)
|
||||
{
|
||||
return $queue ?: $this->default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying database instance.
|
||||
*
|
||||
* @return \Illuminate\Database\Connection
|
||||
*/
|
||||
public function getDatabase()
|
||||
{
|
||||
return $this->database;
|
||||
}
|
||||
}
|
||||
42
vendor/laravel/framework/src/Illuminate/Queue/Events/JobExceptionOccurred.php
vendored
Normal file
42
vendor/laravel/framework/src/Illuminate/Queue/Events/JobExceptionOccurred.php
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Queue\Events;
|
||||
|
||||
class JobExceptionOccurred
|
||||
{
|
||||
/**
|
||||
* The connection name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $connectionName;
|
||||
|
||||
/**
|
||||
* The job instance.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Queue\Job
|
||||
*/
|
||||
public $job;
|
||||
|
||||
/**
|
||||
* The exception instance.
|
||||
*
|
||||
* @var \Throwable
|
||||
*/
|
||||
public $exception;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param string $connectionName
|
||||
* @param \Illuminate\Contracts\Queue\Job $job
|
||||
* @param \Throwable $exception
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($connectionName, $job, $exception)
|
||||
{
|
||||
$this->job = $job;
|
||||
$this->exception = $exception;
|
||||
$this->connectionName = $connectionName;
|
||||
}
|
||||
}
|
||||
42
vendor/laravel/framework/src/Illuminate/Queue/Events/JobFailed.php
vendored
Normal file
42
vendor/laravel/framework/src/Illuminate/Queue/Events/JobFailed.php
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Queue\Events;
|
||||
|
||||
class JobFailed
|
||||
{
|
||||
/**
|
||||
* The connection name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $connectionName;
|
||||
|
||||
/**
|
||||
* The job instance.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Queue\Job
|
||||
*/
|
||||
public $job;
|
||||
|
||||
/**
|
||||
* The exception that caused the job to fail.
|
||||
*
|
||||
* @var \Throwable
|
||||
*/
|
||||
public $exception;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param string $connectionName
|
||||
* @param \Illuminate\Contracts\Queue\Job $job
|
||||
* @param \Throwable $exception
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($connectionName, $job, $exception)
|
||||
{
|
||||
$this->job = $job;
|
||||
$this->exception = $exception;
|
||||
$this->connectionName = $connectionName;
|
||||
}
|
||||
}
|
||||
33
vendor/laravel/framework/src/Illuminate/Queue/Events/JobProcessed.php
vendored
Normal file
33
vendor/laravel/framework/src/Illuminate/Queue/Events/JobProcessed.php
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Queue\Events;
|
||||
|
||||
class JobProcessed
|
||||
{
|
||||
/**
|
||||
* The connection name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $connectionName;
|
||||
|
||||
/**
|
||||
* The job instance.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Queue\Job
|
||||
*/
|
||||
public $job;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param string $connectionName
|
||||
* @param \Illuminate\Contracts\Queue\Job $job
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($connectionName, $job)
|
||||
{
|
||||
$this->job = $job;
|
||||
$this->connectionName = $connectionName;
|
||||
}
|
||||
}
|
||||
33
vendor/laravel/framework/src/Illuminate/Queue/Events/JobProcessing.php
vendored
Normal file
33
vendor/laravel/framework/src/Illuminate/Queue/Events/JobProcessing.php
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Queue\Events;
|
||||
|
||||
class JobProcessing
|
||||
{
|
||||
/**
|
||||
* The connection name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $connectionName;
|
||||
|
||||
/**
|
||||
* The job instance.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Queue\Job
|
||||
*/
|
||||
public $job;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param string $connectionName
|
||||
* @param \Illuminate\Contracts\Queue\Job $job
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($connectionName, $job)
|
||||
{
|
||||
$this->job = $job;
|
||||
$this->connectionName = $connectionName;
|
||||
}
|
||||
}
|
||||
33
vendor/laravel/framework/src/Illuminate/Queue/Events/Looping.php
vendored
Normal file
33
vendor/laravel/framework/src/Illuminate/Queue/Events/Looping.php
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Queue\Events;
|
||||
|
||||
class Looping
|
||||
{
|
||||
/**
|
||||
* The connection name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $connectionName;
|
||||
|
||||
/**
|
||||
* The queue name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $queue;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param string $connectionName
|
||||
* @param string $queue
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($connectionName, $queue)
|
||||
{
|
||||
$this->queue = $queue;
|
||||
$this->connectionName = $connectionName;
|
||||
}
|
||||
}
|
||||
24
vendor/laravel/framework/src/Illuminate/Queue/Events/WorkerStopping.php
vendored
Normal file
24
vendor/laravel/framework/src/Illuminate/Queue/Events/WorkerStopping.php
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Queue\Events;
|
||||
|
||||
class WorkerStopping
|
||||
{
|
||||
/**
|
||||
* The exit status.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $status;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param int $status
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($status = 0)
|
||||
{
|
||||
$this->status = $status;
|
||||
}
|
||||
}
|
||||
117
vendor/laravel/framework/src/Illuminate/Queue/Failed/DatabaseFailedJobProvider.php
vendored
Normal file
117
vendor/laravel/framework/src/Illuminate/Queue/Failed/DatabaseFailedJobProvider.php
vendored
Normal file
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Queue\Failed;
|
||||
|
||||
use Illuminate\Database\ConnectionResolverInterface;
|
||||
use Illuminate\Support\Facades\Date;
|
||||
|
||||
class DatabaseFailedJobProvider implements FailedJobProviderInterface
|
||||
{
|
||||
/**
|
||||
* The connection resolver implementation.
|
||||
*
|
||||
* @var \Illuminate\Database\ConnectionResolverInterface
|
||||
*/
|
||||
protected $resolver;
|
||||
|
||||
/**
|
||||
* The database connection name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $database;
|
||||
|
||||
/**
|
||||
* The database table.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table;
|
||||
|
||||
/**
|
||||
* Create a new database failed job provider.
|
||||
*
|
||||
* @param \Illuminate\Database\ConnectionResolverInterface $resolver
|
||||
* @param string $database
|
||||
* @param string $table
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(ConnectionResolverInterface $resolver, $database, $table)
|
||||
{
|
||||
$this->table = $table;
|
||||
$this->resolver = $resolver;
|
||||
$this->database = $database;
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a failed job into storage.
|
||||
*
|
||||
* @param string $connection
|
||||
* @param string $queue
|
||||
* @param string $payload
|
||||
* @param \Throwable $exception
|
||||
* @return int|null
|
||||
*/
|
||||
public function log($connection, $queue, $payload, $exception)
|
||||
{
|
||||
$failed_at = Date::now();
|
||||
|
||||
$exception = (string) $exception;
|
||||
|
||||
return $this->getTable()->insertGetId(compact(
|
||||
'connection', 'queue', 'payload', 'exception', 'failed_at'
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all of the failed jobs.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function all()
|
||||
{
|
||||
return $this->getTable()->orderBy('id', 'desc')->get()->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single failed job.
|
||||
*
|
||||
* @param mixed $id
|
||||
* @return object|null
|
||||
*/
|
||||
public function find($id)
|
||||
{
|
||||
return $this->getTable()->find($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a single failed job from storage.
|
||||
*
|
||||
* @param mixed $id
|
||||
* @return bool
|
||||
*/
|
||||
public function forget($id)
|
||||
{
|
||||
return $this->getTable()->where('id', $id)->delete() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush all of the failed jobs from storage.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function flush()
|
||||
{
|
||||
$this->getTable()->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a new query builder instance for the table.
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Builder
|
||||
*/
|
||||
protected function getTable()
|
||||
{
|
||||
return $this->resolver->connection($this->database)->table($this->table);
|
||||
}
|
||||
}
|
||||
175
vendor/laravel/framework/src/Illuminate/Queue/Failed/DynamoDbFailedJobProvider.php
vendored
Normal file
175
vendor/laravel/framework/src/Illuminate/Queue/Failed/DynamoDbFailedJobProvider.php
vendored
Normal file
@@ -0,0 +1,175 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Queue\Failed;
|
||||
|
||||
use Aws\DynamoDb\DynamoDbClient;
|
||||
use DateTimeInterface;
|
||||
use Exception;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\Date;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class DynamoDbFailedJobProvider implements FailedJobProviderInterface
|
||||
{
|
||||
/**
|
||||
* The DynamoDB client instance.
|
||||
*
|
||||
* @var \Aws\DynamoDb\DynamoDbClient
|
||||
*/
|
||||
protected $dynamo;
|
||||
|
||||
/**
|
||||
* The application name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $applicationName;
|
||||
|
||||
/**
|
||||
* The table name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table;
|
||||
|
||||
/**
|
||||
* Create a new DynamoDb failed job provider.
|
||||
*
|
||||
* @param \Aws\DynamoDb\DynamoDbClient $dynamo
|
||||
* @param string $applicationName
|
||||
* @param string $table
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(DynamoDbClient $dynamo, $applicationName, $table)
|
||||
{
|
||||
$this->table = $table;
|
||||
$this->dynamo = $dynamo;
|
||||
$this->applicationName = $applicationName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a failed job into storage.
|
||||
*
|
||||
* @param string $connection
|
||||
* @param string $queue
|
||||
* @param string $payload
|
||||
* @param \Throwable $exception
|
||||
* @return string|int|null
|
||||
*/
|
||||
public function log($connection, $queue, $payload, $exception)
|
||||
{
|
||||
$id = (string) Str::orderedUuid();
|
||||
|
||||
$failedAt = Date::now();
|
||||
|
||||
$this->dynamo->putItem([
|
||||
'TableName' => $this->table,
|
||||
'Item' => [
|
||||
'application' => ['S' => $this->applicationName],
|
||||
'uuid' => ['S' => $id],
|
||||
'connection' => ['S' => $connection],
|
||||
'queue' => ['S' => $queue],
|
||||
'payload' => ['S' => $payload],
|
||||
'exception' => ['S' => (string) $exception],
|
||||
'failed_at' => ['N' => (string) $failedAt->getTimestamp()],
|
||||
'expires_at' => ['N' => (string) $failedAt->addDays(3)->getTimestamp()],
|
||||
],
|
||||
]);
|
||||
|
||||
return $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all of the failed jobs.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function all()
|
||||
{
|
||||
$results = $this->dynamo->query([
|
||||
'TableName' => $this->table,
|
||||
'Select' => 'ALL_ATTRIBUTES',
|
||||
'KeyConditionExpression' => 'application = :application',
|
||||
'ExpressionAttributeValues' => [
|
||||
':application' => ['S' => $this->applicationName],
|
||||
],
|
||||
'ScanIndexForward' => false,
|
||||
]);
|
||||
|
||||
return collect($results['Items'])->map(function ($result) {
|
||||
return (object) [
|
||||
'id' => $result['uuid']['S'],
|
||||
'connection' => $result['connection']['S'],
|
||||
'queue' => $result['queue']['S'],
|
||||
'payload' => $result['payload']['S'],
|
||||
'exception' => $result['exception']['S'],
|
||||
'failed_at' => Carbon::createFromTimestamp(
|
||||
(int) $result['failed_at']['N']
|
||||
)->format(DateTimeInterface::ISO8601),
|
||||
];
|
||||
})->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single failed job.
|
||||
*
|
||||
* @param mixed $id
|
||||
* @return object|null
|
||||
*/
|
||||
public function find($id)
|
||||
{
|
||||
$result = $this->dynamo->getItem([
|
||||
'TableName' => $this->table,
|
||||
'Key' => [
|
||||
'application' => ['S' => $this->applicationName],
|
||||
'uuid' => ['S' => $id],
|
||||
],
|
||||
]);
|
||||
|
||||
if (! isset($result['Item'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
return (object) [
|
||||
'id' => $result['Item']['uuid']['S'],
|
||||
'connection' => $result['Item']['connection']['S'],
|
||||
'queue' => $result['Item']['queue']['S'],
|
||||
'payload' => $result['Item']['payload']['S'],
|
||||
'exception' => $result['Item']['exception']['S'],
|
||||
'failed_at' => Carbon::createFromTimestamp(
|
||||
(int) $result['Item']['failed_at']['N']
|
||||
)->format(DateTimeInterface::ISO8601),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a single failed job from storage.
|
||||
*
|
||||
* @param mixed $id
|
||||
* @return bool
|
||||
*/
|
||||
public function forget($id)
|
||||
{
|
||||
$this->dynamo->deleteItem([
|
||||
'TableName' => $this->table,
|
||||
'Key' => [
|
||||
'application' => ['S' => $this->applicationName],
|
||||
'uuid' => ['S' => $id],
|
||||
],
|
||||
]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush all of the failed jobs from storage.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function flush()
|
||||
{
|
||||
throw new Exception("DynamoDb failed job storage may not be flushed. Please use DynamoDb's TTL features on your expires_at attribute.");
|
||||
}
|
||||
}
|
||||
47
vendor/laravel/framework/src/Illuminate/Queue/Failed/FailedJobProviderInterface.php
vendored
Normal file
47
vendor/laravel/framework/src/Illuminate/Queue/Failed/FailedJobProviderInterface.php
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Queue\Failed;
|
||||
|
||||
interface FailedJobProviderInterface
|
||||
{
|
||||
/**
|
||||
* Log a failed job into storage.
|
||||
*
|
||||
* @param string $connection
|
||||
* @param string $queue
|
||||
* @param string $payload
|
||||
* @param \Throwable $exception
|
||||
* @return string|int|null
|
||||
*/
|
||||
public function log($connection, $queue, $payload, $exception);
|
||||
|
||||
/**
|
||||
* Get a list of all of the failed jobs.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function all();
|
||||
|
||||
/**
|
||||
* Get a single failed job.
|
||||
*
|
||||
* @param mixed $id
|
||||
* @return object|null
|
||||
*/
|
||||
public function find($id);
|
||||
|
||||
/**
|
||||
* Delete a single failed job from storage.
|
||||
*
|
||||
* @param mixed $id
|
||||
* @return bool
|
||||
*/
|
||||
public function forget($id);
|
||||
|
||||
/**
|
||||
* Flush all of the failed jobs from storage.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function flush();
|
||||
}
|
||||
62
vendor/laravel/framework/src/Illuminate/Queue/Failed/NullFailedJobProvider.php
vendored
Normal file
62
vendor/laravel/framework/src/Illuminate/Queue/Failed/NullFailedJobProvider.php
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Queue\Failed;
|
||||
|
||||
class NullFailedJobProvider implements FailedJobProviderInterface
|
||||
{
|
||||
/**
|
||||
* Log a failed job into storage.
|
||||
*
|
||||
* @param string $connection
|
||||
* @param string $queue
|
||||
* @param string $payload
|
||||
* @param \Throwable $exception
|
||||
* @return int|null
|
||||
*/
|
||||
public function log($connection, $queue, $payload, $exception)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all of the failed jobs.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function all()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single failed job.
|
||||
*
|
||||
* @param mixed $id
|
||||
* @return object|null
|
||||
*/
|
||||
public function find($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a single failed job from storage.
|
||||
*
|
||||
* @param mixed $id
|
||||
* @return bool
|
||||
*/
|
||||
public function forget($id)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush all of the failed jobs from storage.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function flush()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
76
vendor/laravel/framework/src/Illuminate/Queue/InteractsWithQueue.php
vendored
Normal file
76
vendor/laravel/framework/src/Illuminate/Queue/InteractsWithQueue.php
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Queue;
|
||||
|
||||
use Illuminate\Contracts\Queue\Job as JobContract;
|
||||
|
||||
trait InteractsWithQueue
|
||||
{
|
||||
/**
|
||||
* The underlying queue job instance.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Queue\Job
|
||||
*/
|
||||
public $job;
|
||||
|
||||
/**
|
||||
* Get the number of times the job has been attempted.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function attempts()
|
||||
{
|
||||
return $this->job ? $this->job->attempts() : 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the job from the queue.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
if ($this->job) {
|
||||
return $this->job->delete();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fail the job from the queue.
|
||||
*
|
||||
* @param \Throwable|null $exception
|
||||
* @return void
|
||||
*/
|
||||
public function fail($exception = null)
|
||||
{
|
||||
if ($this->job) {
|
||||
$this->job->fail($exception);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Release the job back into the queue.
|
||||
*
|
||||
* @param int $delay
|
||||
* @return void
|
||||
*/
|
||||
public function release($delay = 0)
|
||||
{
|
||||
if ($this->job) {
|
||||
return $this->job->release($delay);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the base queue job instance.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Queue\Job $job
|
||||
* @return $this
|
||||
*/
|
||||
public function setJob(JobContract $job)
|
||||
{
|
||||
$this->job = $job;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
19
vendor/laravel/framework/src/Illuminate/Queue/InvalidPayloadException.php
vendored
Normal file
19
vendor/laravel/framework/src/Illuminate/Queue/InvalidPayloadException.php
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Queue;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
class InvalidPayloadException extends InvalidArgumentException
|
||||
{
|
||||
/**
|
||||
* Create a new exception instance.
|
||||
*
|
||||
* @param string|null $message
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($message = null)
|
||||
{
|
||||
parent::__construct($message ?: json_last_error());
|
||||
}
|
||||
}
|
||||
135
vendor/laravel/framework/src/Illuminate/Queue/Jobs/BeanstalkdJob.php
vendored
Executable file
135
vendor/laravel/framework/src/Illuminate/Queue/Jobs/BeanstalkdJob.php
vendored
Executable file
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Queue\Jobs;
|
||||
|
||||
use Illuminate\Container\Container;
|
||||
use Illuminate\Contracts\Queue\Job as JobContract;
|
||||
use Pheanstalk\Job as PheanstalkJob;
|
||||
use Pheanstalk\Pheanstalk;
|
||||
|
||||
class BeanstalkdJob extends Job implements JobContract
|
||||
{
|
||||
/**
|
||||
* The Pheanstalk instance.
|
||||
*
|
||||
* @var \Pheanstalk\Pheanstalk
|
||||
*/
|
||||
protected $pheanstalk;
|
||||
|
||||
/**
|
||||
* The Pheanstalk job instance.
|
||||
*
|
||||
* @var \Pheanstalk\Job
|
||||
*/
|
||||
protected $job;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param \Illuminate\Container\Container $container
|
||||
* @param \Pheanstalk\Pheanstalk $pheanstalk
|
||||
* @param \Pheanstalk\Job $job
|
||||
* @param string $connectionName
|
||||
* @param string $queue
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Container $container, Pheanstalk $pheanstalk, PheanstalkJob $job, $connectionName, $queue)
|
||||
{
|
||||
$this->job = $job;
|
||||
$this->queue = $queue;
|
||||
$this->container = $container;
|
||||
$this->pheanstalk = $pheanstalk;
|
||||
$this->connectionName = $connectionName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Release the job back into the queue.
|
||||
*
|
||||
* @param int $delay
|
||||
* @return void
|
||||
*/
|
||||
public function release($delay = 0)
|
||||
{
|
||||
parent::release($delay);
|
||||
|
||||
$priority = Pheanstalk::DEFAULT_PRIORITY;
|
||||
|
||||
$this->pheanstalk->release($this->job, $priority, $delay);
|
||||
}
|
||||
|
||||
/**
|
||||
* Bury the job in the queue.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function bury()
|
||||
{
|
||||
parent::release();
|
||||
|
||||
$this->pheanstalk->bury($this->job);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the job from the queue.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
parent::delete();
|
||||
|
||||
$this->pheanstalk->delete($this->job);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of times the job has been attempted.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function attempts()
|
||||
{
|
||||
$stats = $this->pheanstalk->statsJob($this->job);
|
||||
|
||||
return (int) $stats->reserves;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the job identifier.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getJobId()
|
||||
{
|
||||
return $this->job->getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the raw body string for the job.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRawBody()
|
||||
{
|
||||
return $this->job->getData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying Pheanstalk instance.
|
||||
*
|
||||
* @return \Pheanstalk\Pheanstalk
|
||||
*/
|
||||
public function getPheanstalk()
|
||||
{
|
||||
return $this->pheanstalk;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying Pheanstalk job.
|
||||
*
|
||||
* @return \Pheanstalk\Job
|
||||
*/
|
||||
public function getPheanstalkJob()
|
||||
{
|
||||
return $this->job;
|
||||
}
|
||||
}
|
||||
100
vendor/laravel/framework/src/Illuminate/Queue/Jobs/DatabaseJob.php
vendored
Normal file
100
vendor/laravel/framework/src/Illuminate/Queue/Jobs/DatabaseJob.php
vendored
Normal file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Queue\Jobs;
|
||||
|
||||
use Illuminate\Container\Container;
|
||||
use Illuminate\Contracts\Queue\Job as JobContract;
|
||||
use Illuminate\Queue\DatabaseQueue;
|
||||
|
||||
class DatabaseJob extends Job implements JobContract
|
||||
{
|
||||
/**
|
||||
* The database queue instance.
|
||||
*
|
||||
* @var \Illuminate\Queue\DatabaseQueue
|
||||
*/
|
||||
protected $database;
|
||||
|
||||
/**
|
||||
* The database job payload.
|
||||
*
|
||||
* @var \stdClass
|
||||
*/
|
||||
protected $job;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param \Illuminate\Container\Container $container
|
||||
* @param \Illuminate\Queue\DatabaseQueue $database
|
||||
* @param \stdClass $job
|
||||
* @param string $connectionName
|
||||
* @param string $queue
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Container $container, DatabaseQueue $database, $job, $connectionName, $queue)
|
||||
{
|
||||
$this->job = $job;
|
||||
$this->queue = $queue;
|
||||
$this->database = $database;
|
||||
$this->container = $container;
|
||||
$this->connectionName = $connectionName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Release the job back into the queue.
|
||||
*
|
||||
* @param int $delay
|
||||
* @return mixed
|
||||
*/
|
||||
public function release($delay = 0)
|
||||
{
|
||||
parent::release($delay);
|
||||
|
||||
$this->delete();
|
||||
|
||||
return $this->database->release($this->queue, $this->job, $delay);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the job from the queue.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
parent::delete();
|
||||
|
||||
$this->database->deleteReserved($this->queue, $this->job->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of times the job has been attempted.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function attempts()
|
||||
{
|
||||
return (int) $this->job->attempts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the job identifier.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getJobId()
|
||||
{
|
||||
return $this->job->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the raw body string for the job.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRawBody()
|
||||
{
|
||||
return $this->job->payload;
|
||||
}
|
||||
}
|
||||
63
vendor/laravel/framework/src/Illuminate/Queue/Jobs/DatabaseJobRecord.php
vendored
Normal file
63
vendor/laravel/framework/src/Illuminate/Queue/Jobs/DatabaseJobRecord.php
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Queue\Jobs;
|
||||
|
||||
use Illuminate\Support\InteractsWithTime;
|
||||
|
||||
class DatabaseJobRecord
|
||||
{
|
||||
use InteractsWithTime;
|
||||
|
||||
/**
|
||||
* The underlying job record.
|
||||
*
|
||||
* @var \stdClass
|
||||
*/
|
||||
protected $record;
|
||||
|
||||
/**
|
||||
* Create a new job record instance.
|
||||
*
|
||||
* @param \stdClass $record
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($record)
|
||||
{
|
||||
$this->record = $record;
|
||||
}
|
||||
|
||||
/**
|
||||
* Increment the number of times the job has been attempted.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function increment()
|
||||
{
|
||||
$this->record->attempts++;
|
||||
|
||||
return $this->record->attempts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the "reserved at" timestamp of the job.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function touch()
|
||||
{
|
||||
$this->record->reserved_at = $this->currentTime();
|
||||
|
||||
return $this->record->reserved_at;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamically access the underlying job information.
|
||||
*
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function __get($key)
|
||||
{
|
||||
return $this->record->{$key};
|
||||
}
|
||||
}
|
||||
349
vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php
vendored
Executable file
349
vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php
vendored
Executable file
@@ -0,0 +1,349 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Queue\Jobs;
|
||||
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
use Illuminate\Queue\Events\JobFailed;
|
||||
use Illuminate\Queue\ManuallyFailedException;
|
||||
use Illuminate\Support\InteractsWithTime;
|
||||
|
||||
abstract class Job
|
||||
{
|
||||
use InteractsWithTime;
|
||||
|
||||
/**
|
||||
* The job handler instance.
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected $instance;
|
||||
|
||||
/**
|
||||
* The IoC container instance.
|
||||
*
|
||||
* @var \Illuminate\Container\Container
|
||||
*/
|
||||
protected $container;
|
||||
|
||||
/**
|
||||
* Indicates if the job has been deleted.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $deleted = false;
|
||||
|
||||
/**
|
||||
* Indicates if the job has been released.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $released = false;
|
||||
|
||||
/**
|
||||
* Indicates if the job has failed.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $failed = false;
|
||||
|
||||
/**
|
||||
* The name of the connection the job belongs to.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $connectionName;
|
||||
|
||||
/**
|
||||
* The name of the queue the job belongs to.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $queue;
|
||||
|
||||
/**
|
||||
* Get the job identifier.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract public function getJobId();
|
||||
|
||||
/**
|
||||
* Get the raw body of the job.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract public function getRawBody();
|
||||
|
||||
/**
|
||||
* Get the UUID of the job.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function uuid()
|
||||
{
|
||||
return $this->payload()['uuid'] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fire the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function fire()
|
||||
{
|
||||
$payload = $this->payload();
|
||||
|
||||
[$class, $method] = JobName::parse($payload['job']);
|
||||
|
||||
($this->instance = $this->resolve($class))->{$method}($this, $payload['data']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the job from the queue.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$this->deleted = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the job has been deleted.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isDeleted()
|
||||
{
|
||||
return $this->deleted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Release the job back into the queue.
|
||||
*
|
||||
* @param int $delay
|
||||
* @return void
|
||||
*/
|
||||
public function release($delay = 0)
|
||||
{
|
||||
$this->released = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the job was released back into the queue.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isReleased()
|
||||
{
|
||||
return $this->released;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the job has been deleted or released.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isDeletedOrReleased()
|
||||
{
|
||||
return $this->isDeleted() || $this->isReleased();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the job has been marked as a failure.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasFailed()
|
||||
{
|
||||
return $this->failed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark the job as "failed".
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function markAsFailed()
|
||||
{
|
||||
$this->failed = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the job, call the "failed" method, and raise the failed job event.
|
||||
*
|
||||
* @param \Throwable|null $e
|
||||
* @return void
|
||||
*/
|
||||
public function fail($e = null)
|
||||
{
|
||||
$this->markAsFailed();
|
||||
|
||||
if ($this->isDeleted()) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// If the job has failed, we will delete it, call the "failed" method and then call
|
||||
// an event indicating the job has failed so it can be logged if needed. This is
|
||||
// to allow every developer to better keep monitor of their failed queue jobs.
|
||||
$this->delete();
|
||||
|
||||
$this->failed($e);
|
||||
} finally {
|
||||
$this->resolve(Dispatcher::class)->dispatch(new JobFailed(
|
||||
$this->connectionName, $this, $e ?: new ManuallyFailedException
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process an exception that caused the job to fail.
|
||||
*
|
||||
* @param \Throwable|null $e
|
||||
* @return void
|
||||
*/
|
||||
protected function failed($e)
|
||||
{
|
||||
$payload = $this->payload();
|
||||
|
||||
[$class, $method] = JobName::parse($payload['job']);
|
||||
|
||||
if (method_exists($this->instance = $this->resolve($class), 'failed')) {
|
||||
$this->instance->failed($payload['data'], $e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the given class.
|
||||
*
|
||||
* @param string $class
|
||||
* @return mixed
|
||||
*/
|
||||
protected function resolve($class)
|
||||
{
|
||||
return $this->container->make($class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the resolved job handler instance.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getResolvedJob()
|
||||
{
|
||||
return $this->instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the decoded body of the job.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function payload()
|
||||
{
|
||||
return json_decode($this->getRawBody(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of times to attempt a job.
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
public function maxTries()
|
||||
{
|
||||
return $this->payload()['maxTries'] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of times to attempt a job after an exception.
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
public function maxExceptions()
|
||||
{
|
||||
return $this->payload()['maxExceptions'] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of seconds to delay a failed job before retrying it.
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
public function delaySeconds()
|
||||
{
|
||||
return $this->payload()['delay'] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of seconds the job can run.
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
public function timeout()
|
||||
{
|
||||
return $this->payload()['timeout'] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the timestamp indicating when the job should timeout.
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
public function timeoutAt()
|
||||
{
|
||||
return $this->payload()['timeoutAt'] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the queued job class.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->payload()['job'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the resolved name of the queued job class.
|
||||
*
|
||||
* Resolves the name of "wrapped" jobs such as class-based handlers.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function resolveName()
|
||||
{
|
||||
return JobName::resolve($this->getName(), $this->payload());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the connection the job belongs to.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getConnectionName()
|
||||
{
|
||||
return $this->connectionName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the queue the job belongs to.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getQueue()
|
||||
{
|
||||
return $this->queue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the service container instance.
|
||||
*
|
||||
* @return \Illuminate\Container\Container
|
||||
*/
|
||||
public function getContainer()
|
||||
{
|
||||
return $this->container;
|
||||
}
|
||||
}
|
||||
35
vendor/laravel/framework/src/Illuminate/Queue/Jobs/JobName.php
vendored
Normal file
35
vendor/laravel/framework/src/Illuminate/Queue/Jobs/JobName.php
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Queue\Jobs;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class JobName
|
||||
{
|
||||
/**
|
||||
* Parse the given job name into a class / method array.
|
||||
*
|
||||
* @param string $job
|
||||
* @return array
|
||||
*/
|
||||
public static function parse($job)
|
||||
{
|
||||
return Str::parseCallback($job, 'fire');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the resolved name of the queued job class.
|
||||
*
|
||||
* @param string $name
|
||||
* @param array $payload
|
||||
* @return string
|
||||
*/
|
||||
public static function resolve($name, $payload)
|
||||
{
|
||||
if (! empty($payload['displayName'])) {
|
||||
return $payload['displayName'];
|
||||
}
|
||||
|
||||
return $name;
|
||||
}
|
||||
}
|
||||
139
vendor/laravel/framework/src/Illuminate/Queue/Jobs/RedisJob.php
vendored
Normal file
139
vendor/laravel/framework/src/Illuminate/Queue/Jobs/RedisJob.php
vendored
Normal file
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Queue\Jobs;
|
||||
|
||||
use Illuminate\Container\Container;
|
||||
use Illuminate\Contracts\Queue\Job as JobContract;
|
||||
use Illuminate\Queue\RedisQueue;
|
||||
|
||||
class RedisJob extends Job implements JobContract
|
||||
{
|
||||
/**
|
||||
* The Redis queue instance.
|
||||
*
|
||||
* @var \Illuminate\Queue\RedisQueue
|
||||
*/
|
||||
protected $redis;
|
||||
|
||||
/**
|
||||
* The Redis raw job payload.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $job;
|
||||
|
||||
/**
|
||||
* The JSON decoded version of "$job".
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $decoded;
|
||||
|
||||
/**
|
||||
* The Redis job payload inside the reserved queue.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $reserved;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param \Illuminate\Container\Container $container
|
||||
* @param \Illuminate\Queue\RedisQueue $redis
|
||||
* @param string $job
|
||||
* @param string $reserved
|
||||
* @param string $connectionName
|
||||
* @param string $queue
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Container $container, RedisQueue $redis, $job, $reserved, $connectionName, $queue)
|
||||
{
|
||||
// The $job variable is the original job JSON as it existed in the ready queue while
|
||||
// the $reserved variable is the raw JSON in the reserved queue. The exact format
|
||||
// of the reserved job is required in order for us to properly delete its data.
|
||||
$this->job = $job;
|
||||
$this->redis = $redis;
|
||||
$this->queue = $queue;
|
||||
$this->reserved = $reserved;
|
||||
$this->container = $container;
|
||||
$this->connectionName = $connectionName;
|
||||
|
||||
$this->decoded = $this->payload();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the raw body string for the job.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRawBody()
|
||||
{
|
||||
return $this->job;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the job from the queue.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
parent::delete();
|
||||
|
||||
$this->redis->deleteReserved($this->queue, $this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Release the job back into the queue.
|
||||
*
|
||||
* @param int $delay
|
||||
* @return void
|
||||
*/
|
||||
public function release($delay = 0)
|
||||
{
|
||||
parent::release($delay);
|
||||
|
||||
$this->redis->deleteAndRelease($this->queue, $this, $delay);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of times the job has been attempted.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function attempts()
|
||||
{
|
||||
return ($this->decoded['attempts'] ?? null) + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the job identifier.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getJobId()
|
||||
{
|
||||
return $this->decoded['id'] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying Redis factory implementation.
|
||||
*
|
||||
* @return \Illuminate\Queue\RedisQueue
|
||||
*/
|
||||
public function getRedisQueue()
|
||||
{
|
||||
return $this->redis;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying reserved Redis job.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getReservedJob()
|
||||
{
|
||||
return $this->reserved;
|
||||
}
|
||||
}
|
||||
124
vendor/laravel/framework/src/Illuminate/Queue/Jobs/SqsJob.php
vendored
Executable file
124
vendor/laravel/framework/src/Illuminate/Queue/Jobs/SqsJob.php
vendored
Executable file
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Queue\Jobs;
|
||||
|
||||
use Aws\Sqs\SqsClient;
|
||||
use Illuminate\Container\Container;
|
||||
use Illuminate\Contracts\Queue\Job as JobContract;
|
||||
|
||||
class SqsJob extends Job implements JobContract
|
||||
{
|
||||
/**
|
||||
* The Amazon SQS client instance.
|
||||
*
|
||||
* @var \Aws\Sqs\SqsClient
|
||||
*/
|
||||
protected $sqs;
|
||||
|
||||
/**
|
||||
* The Amazon SQS job instance.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $job;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param \Illuminate\Container\Container $container
|
||||
* @param \Aws\Sqs\SqsClient $sqs
|
||||
* @param array $job
|
||||
* @param string $connectionName
|
||||
* @param string $queue
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Container $container, SqsClient $sqs, array $job, $connectionName, $queue)
|
||||
{
|
||||
$this->sqs = $sqs;
|
||||
$this->job = $job;
|
||||
$this->queue = $queue;
|
||||
$this->container = $container;
|
||||
$this->connectionName = $connectionName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Release the job back into the queue.
|
||||
*
|
||||
* @param int $delay
|
||||
* @return void
|
||||
*/
|
||||
public function release($delay = 0)
|
||||
{
|
||||
parent::release($delay);
|
||||
|
||||
$this->sqs->changeMessageVisibility([
|
||||
'QueueUrl' => $this->queue,
|
||||
'ReceiptHandle' => $this->job['ReceiptHandle'],
|
||||
'VisibilityTimeout' => $delay,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the job from the queue.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
parent::delete();
|
||||
|
||||
$this->sqs->deleteMessage([
|
||||
'QueueUrl' => $this->queue, 'ReceiptHandle' => $this->job['ReceiptHandle'],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of times the job has been attempted.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function attempts()
|
||||
{
|
||||
return (int) $this->job['Attributes']['ApproximateReceiveCount'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the job identifier.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getJobId()
|
||||
{
|
||||
return $this->job['MessageId'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the raw body string for the job.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRawBody()
|
||||
{
|
||||
return $this->job['Body'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying SQS client instance.
|
||||
*
|
||||
* @return \Aws\Sqs\SqsClient
|
||||
*/
|
||||
public function getSqs()
|
||||
{
|
||||
return $this->sqs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying raw SQS job.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSqsJob()
|
||||
{
|
||||
return $this->job;
|
||||
}
|
||||
}
|
||||
91
vendor/laravel/framework/src/Illuminate/Queue/Jobs/SyncJob.php
vendored
Executable file
91
vendor/laravel/framework/src/Illuminate/Queue/Jobs/SyncJob.php
vendored
Executable file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Queue\Jobs;
|
||||
|
||||
use Illuminate\Container\Container;
|
||||
use Illuminate\Contracts\Queue\Job as JobContract;
|
||||
|
||||
class SyncJob extends Job implements JobContract
|
||||
{
|
||||
/**
|
||||
* The class name of the job.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $job;
|
||||
|
||||
/**
|
||||
* The queue message data.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $payload;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param \Illuminate\Container\Container $container
|
||||
* @param string $payload
|
||||
* @param string $connectionName
|
||||
* @param string $queue
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Container $container, $payload, $connectionName, $queue)
|
||||
{
|
||||
$this->queue = $queue;
|
||||
$this->payload = $payload;
|
||||
$this->container = $container;
|
||||
$this->connectionName = $connectionName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Release the job back into the queue.
|
||||
*
|
||||
* @param int $delay
|
||||
* @return void
|
||||
*/
|
||||
public function release($delay = 0)
|
||||
{
|
||||
parent::release($delay);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of times the job has been attempted.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function attempts()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the job identifier.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getJobId()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the raw body string for the job.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRawBody()
|
||||
{
|
||||
return $this->payload;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the queue the job belongs to.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getQueue()
|
||||
{
|
||||
return 'sync';
|
||||
}
|
||||
}
|
||||
21
vendor/laravel/framework/src/Illuminate/Queue/LICENSE.md
vendored
Normal file
21
vendor/laravel/framework/src/Illuminate/Queue/LICENSE.md
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) Taylor Otwell
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
230
vendor/laravel/framework/src/Illuminate/Queue/Listener.php
vendored
Executable file
230
vendor/laravel/framework/src/Illuminate/Queue/Listener.php
vendored
Executable file
@@ -0,0 +1,230 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Queue;
|
||||
|
||||
use Closure;
|
||||
use Symfony\Component\Process\PhpExecutableFinder;
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
class Listener
|
||||
{
|
||||
/**
|
||||
* The command working path.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $commandPath;
|
||||
|
||||
/**
|
||||
* The environment the workers should run under.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $environment;
|
||||
|
||||
/**
|
||||
* The amount of seconds to wait before polling the queue.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $sleep = 3;
|
||||
|
||||
/**
|
||||
* The amount of times to try a job before logging it failed.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $maxTries = 0;
|
||||
|
||||
/**
|
||||
* The output handler callback.
|
||||
*
|
||||
* @var \Closure|null
|
||||
*/
|
||||
protected $outputHandler;
|
||||
|
||||
/**
|
||||
* Create a new queue listener.
|
||||
*
|
||||
* @param string $commandPath
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($commandPath)
|
||||
{
|
||||
$this->commandPath = $commandPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the PHP binary.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function phpBinary()
|
||||
{
|
||||
return (new PhpExecutableFinder)->find(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Artisan binary.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function artisanBinary()
|
||||
{
|
||||
return defined('ARTISAN_BINARY') ? ARTISAN_BINARY : 'artisan';
|
||||
}
|
||||
|
||||
/**
|
||||
* Listen to the given queue connection.
|
||||
*
|
||||
* @param string $connection
|
||||
* @param string $queue
|
||||
* @param \Illuminate\Queue\ListenerOptions $options
|
||||
* @return void
|
||||
*/
|
||||
public function listen($connection, $queue, ListenerOptions $options)
|
||||
{
|
||||
$process = $this->makeProcess($connection, $queue, $options);
|
||||
|
||||
while (true) {
|
||||
$this->runProcess($process, $options->memory);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new Symfony process for the worker.
|
||||
*
|
||||
* @param string $connection
|
||||
* @param string $queue
|
||||
* @param \Illuminate\Queue\ListenerOptions $options
|
||||
* @return \Symfony\Component\Process\Process
|
||||
*/
|
||||
public function makeProcess($connection, $queue, ListenerOptions $options)
|
||||
{
|
||||
$command = $this->createCommand(
|
||||
$connection,
|
||||
$queue,
|
||||
$options
|
||||
);
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
return new Process(
|
||||
$command,
|
||||
$this->commandPath,
|
||||
null,
|
||||
null,
|
||||
$options->timeout
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the environment option to the given command.
|
||||
*
|
||||
* @param array $command
|
||||
* @param \Illuminate\Queue\ListenerOptions $options
|
||||
* @return array
|
||||
*/
|
||||
protected function addEnvironment($command, ListenerOptions $options)
|
||||
{
|
||||
return array_merge($command, ["--env={$options->environment}"]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the command with the listener options.
|
||||
*
|
||||
* @param string $connection
|
||||
* @param string $queue
|
||||
* @param \Illuminate\Queue\ListenerOptions $options
|
||||
* @return array
|
||||
*/
|
||||
protected function createCommand($connection, $queue, ListenerOptions $options)
|
||||
{
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the given process.
|
||||
*
|
||||
* @param \Symfony\Component\Process\Process $process
|
||||
* @param int $memory
|
||||
* @return void
|
||||
*/
|
||||
public function runProcess(Process $process, $memory)
|
||||
{
|
||||
$process->run(function ($type, $line) {
|
||||
$this->handleWorkerOutput($type, $line);
|
||||
});
|
||||
|
||||
// Once we have run the job we'll go check if the memory limit has been exceeded
|
||||
// for the script. If it has, we will kill this script so the process manager
|
||||
// will restart this with a clean slate of memory automatically on exiting.
|
||||
if ($this->memoryExceeded($memory)) {
|
||||
$this->stop();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle output from the worker process.
|
||||
*
|
||||
* @param int $type
|
||||
* @param string $line
|
||||
* @return void
|
||||
*/
|
||||
protected function handleWorkerOutput($type, $line)
|
||||
{
|
||||
if (isset($this->outputHandler)) {
|
||||
call_user_func($this->outputHandler, $type, $line);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the memory limit has been exceeded.
|
||||
*
|
||||
* @param int $memoryLimit
|
||||
* @return bool
|
||||
*/
|
||||
public function memoryExceeded($memoryLimit)
|
||||
{
|
||||
return (memory_get_usage(true) / 1024 / 1024) >= $memoryLimit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop listening and bail out of the script.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function stop()
|
||||
{
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the output handler callback.
|
||||
*
|
||||
* @param \Closure $outputHandler
|
||||
* @return void
|
||||
*/
|
||||
public function setOutputHandler(Closure $outputHandler)
|
||||
{
|
||||
$this->outputHandler = $outputHandler;
|
||||
}
|
||||
}
|
||||
32
vendor/laravel/framework/src/Illuminate/Queue/ListenerOptions.php
vendored
Normal file
32
vendor/laravel/framework/src/Illuminate/Queue/ListenerOptions.php
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Queue;
|
||||
|
||||
class ListenerOptions extends WorkerOptions
|
||||
{
|
||||
/**
|
||||
* The environment the worker should run in.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $environment;
|
||||
|
||||
/**
|
||||
* Create a new listener options instance.
|
||||
*
|
||||
* @param string|null $environment
|
||||
* @param int $delay
|
||||
* @param int $memory
|
||||
* @param int $timeout
|
||||
* @param int $sleep
|
||||
* @param int $maxTries
|
||||
* @param bool $force
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($environment = null, $delay = 0, $memory = 128, $timeout = 60, $sleep = 3, $maxTries = 1, $force = false)
|
||||
{
|
||||
$this->environment = $environment;
|
||||
|
||||
parent::__construct($delay, $memory, $timeout, $sleep, $maxTries, $force);
|
||||
}
|
||||
}
|
||||
129
vendor/laravel/framework/src/Illuminate/Queue/LuaScripts.php
vendored
Normal file
129
vendor/laravel/framework/src/Illuminate/Queue/LuaScripts.php
vendored
Normal file
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Queue;
|
||||
|
||||
class LuaScripts
|
||||
{
|
||||
/**
|
||||
* Get the Lua script for computing the size of queue.
|
||||
*
|
||||
* KEYS[1] - The name of the primary queue
|
||||
* KEYS[2] - The name of the "delayed" queue
|
||||
* KEYS[3] - The name of the "reserved" queue
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function size()
|
||||
{
|
||||
return <<<'LUA'
|
||||
return redis.call('llen', KEYS[1]) + redis.call('zcard', KEYS[2]) + redis.call('zcard', KEYS[3])
|
||||
LUA;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Lua script for pushing jobs onto the queue.
|
||||
*
|
||||
* KEYS[1] - The queue to push the job onto, for example: queues:foo
|
||||
* KEYS[2] - The notification list fot the queue we are pushing jobs onto, for example: queues:foo:notify
|
||||
* ARGV[1] - The job payload
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function push()
|
||||
{
|
||||
return <<<'LUA'
|
||||
-- Push the job onto the queue...
|
||||
redis.call('rpush', KEYS[1], ARGV[1])
|
||||
-- Push a notification onto the "notify" queue...
|
||||
redis.call('rpush', KEYS[2], 1)
|
||||
LUA;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Lua script for popping the next job off of the queue.
|
||||
*
|
||||
* KEYS[1] - The queue to pop jobs from, for example: queues:foo
|
||||
* KEYS[2] - The queue to place reserved jobs on, for example: queues:foo:reserved
|
||||
* KEYS[3] - The notify queue
|
||||
* ARGV[1] - The time at which the reserved job will expire
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function pop()
|
||||
{
|
||||
return <<<'LUA'
|
||||
-- Pop the first job off of the queue...
|
||||
local job = redis.call('lpop', KEYS[1])
|
||||
local reserved = false
|
||||
|
||||
if(job ~= false) then
|
||||
-- Increment the attempt count and place job on the reserved queue...
|
||||
reserved = cjson.decode(job)
|
||||
reserved['attempts'] = reserved['attempts'] + 1
|
||||
reserved = cjson.encode(reserved)
|
||||
redis.call('zadd', KEYS[2], ARGV[1], reserved)
|
||||
redis.call('lpop', KEYS[3])
|
||||
end
|
||||
|
||||
return {job, reserved}
|
||||
LUA;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Lua script for releasing reserved jobs.
|
||||
*
|
||||
* KEYS[1] - The "delayed" queue we release jobs onto, for example: queues:foo:delayed
|
||||
* KEYS[2] - The queue the jobs are currently on, for example: queues:foo:reserved
|
||||
* ARGV[1] - The raw payload of the job to add to the "delayed" queue
|
||||
* ARGV[2] - The UNIX timestamp at which the job should become available
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function release()
|
||||
{
|
||||
return <<<'LUA'
|
||||
-- Remove the job from the current queue...
|
||||
redis.call('zrem', KEYS[2], ARGV[1])
|
||||
|
||||
-- Add the job onto the "delayed" queue...
|
||||
redis.call('zadd', KEYS[1], ARGV[2], ARGV[1])
|
||||
|
||||
return true
|
||||
LUA;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Lua script to migrate expired jobs back onto the queue.
|
||||
*
|
||||
* KEYS[1] - The queue we are removing jobs from, for example: queues:foo:reserved
|
||||
* KEYS[2] - The queue we are moving jobs to, for example: queues:foo
|
||||
* KEYS[3] - The notification list for the queue we are moving jobs to, for example queues:foo:notify
|
||||
* ARGV[1] - The current UNIX timestamp
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function migrateExpiredJobs()
|
||||
{
|
||||
return <<<'LUA'
|
||||
-- Get all of the jobs with an expired "score"...
|
||||
local val = redis.call('zrangebyscore', KEYS[1], '-inf', ARGV[1])
|
||||
|
||||
-- If we have values in the array, we will remove them from the first queue
|
||||
-- and add them onto the destination queue in chunks of 100, which moves
|
||||
-- all of the appropriate jobs onto the destination queue very safely.
|
||||
if(next(val) ~= nil) then
|
||||
redis.call('zremrangebyrank', KEYS[1], 0, #val - 1)
|
||||
|
||||
for i = 1, #val, 100 do
|
||||
redis.call('rpush', KEYS[2], unpack(val, i, math.min(i+99, #val)))
|
||||
-- Push a notification for every job that was migrated...
|
||||
for j = i, math.min(i+99, #val) do
|
||||
redis.call('rpush', KEYS[3], 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return val
|
||||
LUA;
|
||||
}
|
||||
}
|
||||
10
vendor/laravel/framework/src/Illuminate/Queue/ManuallyFailedException.php
vendored
Normal file
10
vendor/laravel/framework/src/Illuminate/Queue/ManuallyFailedException.php
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Queue;
|
||||
|
||||
use RuntimeException;
|
||||
|
||||
class ManuallyFailedException extends RuntimeException
|
||||
{
|
||||
//
|
||||
}
|
||||
10
vendor/laravel/framework/src/Illuminate/Queue/MaxAttemptsExceededException.php
vendored
Normal file
10
vendor/laravel/framework/src/Illuminate/Queue/MaxAttemptsExceededException.php
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Queue;
|
||||
|
||||
use RuntimeException;
|
||||
|
||||
class MaxAttemptsExceededException extends RuntimeException
|
||||
{
|
||||
//
|
||||
}
|
||||
70
vendor/laravel/framework/src/Illuminate/Queue/NullQueue.php
vendored
Normal file
70
vendor/laravel/framework/src/Illuminate/Queue/NullQueue.php
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Queue;
|
||||
|
||||
use Illuminate\Contracts\Queue\Queue as QueueContract;
|
||||
|
||||
class NullQueue extends Queue implements QueueContract
|
||||
{
|
||||
/**
|
||||
* Get the size of the queue.
|
||||
*
|
||||
* @param string|null $queue
|
||||
* @return int
|
||||
*/
|
||||
public function size($queue = null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Push a new job onto the queue.
|
||||
*
|
||||
* @param string $job
|
||||
* @param mixed $data
|
||||
* @param string|null $queue
|
||||
* @return mixed
|
||||
*/
|
||||
public function push($job, $data = '', $queue = null)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Push a raw payload onto the queue.
|
||||
*
|
||||
* @param string $payload
|
||||
* @param string|null $queue
|
||||
* @param array $options
|
||||
* @return mixed
|
||||
*/
|
||||
public function pushRaw($payload, $queue = null, array $options = [])
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Push a new job onto the queue after a delay.
|
||||
*
|
||||
* @param \DateTimeInterface|\DateInterval|int $delay
|
||||
* @param string $job
|
||||
* @param mixed $data
|
||||
* @param string|null $queue
|
||||
* @return mixed
|
||||
*/
|
||||
public function later($delay, $job, $data = '', $queue = null)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Pop the next job off of the queue.
|
||||
*
|
||||
* @param string|null $queue
|
||||
* @return \Illuminate\Contracts\Queue\Job|null
|
||||
*/
|
||||
public function pop($queue = null)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
290
vendor/laravel/framework/src/Illuminate/Queue/Queue.php
vendored
Executable file
290
vendor/laravel/framework/src/Illuminate/Queue/Queue.php
vendored
Executable file
@@ -0,0 +1,290 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Queue;
|
||||
|
||||
use Closure;
|
||||
use DateTimeInterface;
|
||||
use Illuminate\Container\Container;
|
||||
use Illuminate\Support\InteractsWithTime;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
abstract class Queue
|
||||
{
|
||||
use InteractsWithTime;
|
||||
|
||||
/**
|
||||
* The IoC container instance.
|
||||
*
|
||||
* @var \Illuminate\Container\Container
|
||||
*/
|
||||
protected $container;
|
||||
|
||||
/**
|
||||
* The connection name for the queue.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $connectionName;
|
||||
|
||||
/**
|
||||
* The create payload callbacks.
|
||||
*
|
||||
* @var callable[]
|
||||
*/
|
||||
protected static $createPayloadCallbacks = [];
|
||||
|
||||
/**
|
||||
* Push a new job onto the queue.
|
||||
*
|
||||
* @param string $queue
|
||||
* @param string $job
|
||||
* @param mixed $data
|
||||
* @return mixed
|
||||
*/
|
||||
public function pushOn($queue, $job, $data = '')
|
||||
{
|
||||
return $this->push($job, $data, $queue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Push a new job onto the queue after a delay.
|
||||
*
|
||||
* @param string $queue
|
||||
* @param \DateTimeInterface|\DateInterval|int $delay
|
||||
* @param string $job
|
||||
* @param mixed $data
|
||||
* @return mixed
|
||||
*/
|
||||
public function laterOn($queue, $delay, $job, $data = '')
|
||||
{
|
||||
return $this->later($delay, $job, $data, $queue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Push an array of jobs onto the queue.
|
||||
*
|
||||
* @param array $jobs
|
||||
* @param mixed $data
|
||||
* @param string|null $queue
|
||||
* @return void
|
||||
*/
|
||||
public function bulk($jobs, $data = '', $queue = null)
|
||||
{
|
||||
foreach ((array) $jobs as $job) {
|
||||
$this->push($job, $data, $queue);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a payload string from the given job and data.
|
||||
*
|
||||
* @param \Closure|string|object $job
|
||||
* @param string $queue
|
||||
* @param mixed $data
|
||||
* @return string
|
||||
*
|
||||
* @throws \Illuminate\Queue\InvalidPayloadException
|
||||
*/
|
||||
protected function createPayload($job, $queue, $data = '')
|
||||
{
|
||||
if ($job instanceof Closure) {
|
||||
$job = CallQueuedClosure::create($job);
|
||||
}
|
||||
|
||||
$payload = json_encode($this->createPayloadArray($job, $queue, $data));
|
||||
|
||||
if (JSON_ERROR_NONE !== json_last_error()) {
|
||||
throw new InvalidPayloadException(
|
||||
'Unable to JSON encode payload. Error code: '.json_last_error()
|
||||
);
|
||||
}
|
||||
|
||||
return $payload;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a payload array from the given job and data.
|
||||
*
|
||||
* @param string|object $job
|
||||
* @param string $queue
|
||||
* @param mixed $data
|
||||
* @return array
|
||||
*/
|
||||
protected function createPayloadArray($job, $queue, $data = '')
|
||||
{
|
||||
return is_object($job)
|
||||
? $this->createObjectPayload($job, $queue)
|
||||
: $this->createStringPayload($job, $queue, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a payload for an object-based queue handler.
|
||||
*
|
||||
* @param object $job
|
||||
* @param string $queue
|
||||
* @return array
|
||||
*/
|
||||
protected function createObjectPayload($job, $queue)
|
||||
{
|
||||
$payload = $this->withCreatePayloadHooks($queue, [
|
||||
'uuid' => (string) Str::uuid(),
|
||||
'displayName' => $this->getDisplayName($job),
|
||||
'job' => 'Illuminate\Queue\CallQueuedHandler@call',
|
||||
'maxTries' => $job->tries ?? null,
|
||||
'maxExceptions' => $job->maxExceptions ?? null,
|
||||
'delay' => $this->getJobRetryDelay($job),
|
||||
'timeout' => $job->timeout ?? null,
|
||||
'timeoutAt' => $this->getJobExpiration($job),
|
||||
'data' => [
|
||||
'commandName' => $job,
|
||||
'command' => $job,
|
||||
],
|
||||
]);
|
||||
|
||||
return array_merge($payload, [
|
||||
'data' => [
|
||||
'commandName' => get_class($job),
|
||||
'command' => serialize(clone $job),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the display name for the given job.
|
||||
*
|
||||
* @param object $job
|
||||
* @return string
|
||||
*/
|
||||
protected function getDisplayName($job)
|
||||
{
|
||||
return method_exists($job, 'displayName')
|
||||
? $job->displayName() : get_class($job);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the retry delay for an object-based queue handler.
|
||||
*
|
||||
* @param mixed $job
|
||||
* @return mixed
|
||||
*/
|
||||
public function getJobRetryDelay($job)
|
||||
{
|
||||
if (! method_exists($job, 'retryAfter') && ! isset($job->retryAfter)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$delay = $job->retryAfter ?? $job->retryAfter();
|
||||
|
||||
return $delay instanceof DateTimeInterface
|
||||
? $this->secondsUntil($delay) : $delay;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the expiration timestamp for an object-based queue handler.
|
||||
*
|
||||
* @param mixed $job
|
||||
* @return mixed
|
||||
*/
|
||||
public function getJobExpiration($job)
|
||||
{
|
||||
if (! method_exists($job, 'retryUntil') && ! isset($job->timeoutAt)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$expiration = $job->timeoutAt ?? $job->retryUntil();
|
||||
|
||||
return $expiration instanceof DateTimeInterface
|
||||
? $expiration->getTimestamp() : $expiration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a typical, string based queue payload array.
|
||||
*
|
||||
* @param string $job
|
||||
* @param string $queue
|
||||
* @param mixed $data
|
||||
* @return array
|
||||
*/
|
||||
protected function createStringPayload($job, $queue, $data)
|
||||
{
|
||||
return $this->withCreatePayloadHooks($queue, [
|
||||
'uuid' => (string) Str::uuid(),
|
||||
'displayName' => is_string($job) ? explode('@', $job)[0] : null,
|
||||
'job' => $job,
|
||||
'maxTries' => null,
|
||||
'maxExceptions' => null,
|
||||
'delay' => null,
|
||||
'timeout' => null,
|
||||
'data' => $data,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a callback to be executed when creating job payloads.
|
||||
*
|
||||
* @param callable $callback
|
||||
* @return void
|
||||
*/
|
||||
public static function createPayloadUsing($callback)
|
||||
{
|
||||
if (is_null($callback)) {
|
||||
static::$createPayloadCallbacks = [];
|
||||
} else {
|
||||
static::$createPayloadCallbacks[] = $callback;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the given payload using any registered payload hooks.
|
||||
*
|
||||
* @param string $queue
|
||||
* @param array $payload
|
||||
* @return array
|
||||
*/
|
||||
protected function withCreatePayloadHooks($queue, array $payload)
|
||||
{
|
||||
if (! empty(static::$createPayloadCallbacks)) {
|
||||
foreach (static::$createPayloadCallbacks as $callback) {
|
||||
$payload = array_merge($payload, call_user_func(
|
||||
$callback, $this->getConnectionName(), $queue, $payload
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
return $payload;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the connection name for the queue.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getConnectionName()
|
||||
{
|
||||
return $this->connectionName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the connection name for the queue.
|
||||
*
|
||||
* @param string $name
|
||||
* @return $this
|
||||
*/
|
||||
public function setConnectionName($name)
|
||||
{
|
||||
$this->connectionName = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the IoC container instance.
|
||||
*
|
||||
* @param \Illuminate\Container\Container $container
|
||||
* @return void
|
||||
*/
|
||||
public function setContainer(Container $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
}
|
||||
260
vendor/laravel/framework/src/Illuminate/Queue/QueueManager.php
vendored
Executable file
260
vendor/laravel/framework/src/Illuminate/Queue/QueueManager.php
vendored
Executable file
@@ -0,0 +1,260 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Queue;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Queue\Factory as FactoryContract;
|
||||
use Illuminate\Contracts\Queue\Monitor as MonitorContract;
|
||||
use InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* @mixin \Illuminate\Contracts\Queue\Queue
|
||||
*/
|
||||
class QueueManager implements FactoryContract, MonitorContract
|
||||
{
|
||||
/**
|
||||
* The application instance.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Foundation\Application
|
||||
*/
|
||||
protected $app;
|
||||
|
||||
/**
|
||||
* The array of resolved queue connections.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $connections = [];
|
||||
|
||||
/**
|
||||
* The array of resolved queue connectors.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $connectors = [];
|
||||
|
||||
/**
|
||||
* Create a new queue manager instance.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Foundation\Application $app
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($app)
|
||||
{
|
||||
$this->app = $app;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register an event listener for the before job event.
|
||||
*
|
||||
* @param mixed $callback
|
||||
* @return void
|
||||
*/
|
||||
public function before($callback)
|
||||
{
|
||||
$this->app['events']->listen(Events\JobProcessing::class, $callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register an event listener for the after job event.
|
||||
*
|
||||
* @param mixed $callback
|
||||
* @return void
|
||||
*/
|
||||
public function after($callback)
|
||||
{
|
||||
$this->app['events']->listen(Events\JobProcessed::class, $callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register an event listener for the exception occurred job event.
|
||||
*
|
||||
* @param mixed $callback
|
||||
* @return void
|
||||
*/
|
||||
public function exceptionOccurred($callback)
|
||||
{
|
||||
$this->app['events']->listen(Events\JobExceptionOccurred::class, $callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register an event listener for the daemon queue loop.
|
||||
*
|
||||
* @param mixed $callback
|
||||
* @return void
|
||||
*/
|
||||
public function looping($callback)
|
||||
{
|
||||
$this->app['events']->listen(Events\Looping::class, $callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register an event listener for the failed job event.
|
||||
*
|
||||
* @param mixed $callback
|
||||
* @return void
|
||||
*/
|
||||
public function failing($callback)
|
||||
{
|
||||
$this->app['events']->listen(Events\JobFailed::class, $callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register an event listener for the daemon queue stopping.
|
||||
*
|
||||
* @param mixed $callback
|
||||
* @return void
|
||||
*/
|
||||
public function stopping($callback)
|
||||
{
|
||||
$this->app['events']->listen(Events\WorkerStopping::class, $callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the driver is connected.
|
||||
*
|
||||
* @param string|null $name
|
||||
* @return bool
|
||||
*/
|
||||
public function connected($name = null)
|
||||
{
|
||||
return isset($this->connections[$name ?: $this->getDefaultDriver()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve a queue connection instance.
|
||||
*
|
||||
* @param string|null $name
|
||||
* @return \Illuminate\Contracts\Queue\Queue
|
||||
*/
|
||||
public function connection($name = null)
|
||||
{
|
||||
$name = $name ?: $this->getDefaultDriver();
|
||||
|
||||
// If the connection has not been resolved yet we will resolve it now as all
|
||||
// of the connections are resolved when they are actually needed so we do
|
||||
// not make any unnecessary connection to the various queue end-points.
|
||||
if (! isset($this->connections[$name])) {
|
||||
$this->connections[$name] = $this->resolve($name);
|
||||
|
||||
$this->connections[$name]->setContainer($this->app);
|
||||
}
|
||||
|
||||
return $this->connections[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve a queue connection.
|
||||
*
|
||||
* @param string $name
|
||||
* @return \Illuminate\Contracts\Queue\Queue
|
||||
*/
|
||||
protected function resolve($name)
|
||||
{
|
||||
$config = $this->getConfig($name);
|
||||
|
||||
return $this->getConnector($config['driver'])
|
||||
->connect($config)
|
||||
->setConnectionName($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the connector for a given driver.
|
||||
*
|
||||
* @param string $driver
|
||||
* @return \Illuminate\Queue\Connectors\ConnectorInterface
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
protected function getConnector($driver)
|
||||
{
|
||||
if (! isset($this->connectors[$driver])) {
|
||||
throw new InvalidArgumentException("No connector for [$driver].");
|
||||
}
|
||||
|
||||
return call_user_func($this->connectors[$driver]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a queue connection resolver.
|
||||
*
|
||||
* @param string $driver
|
||||
* @param \Closure $resolver
|
||||
* @return void
|
||||
*/
|
||||
public function extend($driver, Closure $resolver)
|
||||
{
|
||||
return $this->addConnector($driver, $resolver);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a queue connection resolver.
|
||||
*
|
||||
* @param string $driver
|
||||
* @param \Closure $resolver
|
||||
* @return void
|
||||
*/
|
||||
public function addConnector($driver, Closure $resolver)
|
||||
{
|
||||
$this->connectors[$driver] = $resolver;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the queue connection configuration.
|
||||
*
|
||||
* @param string $name
|
||||
* @return array
|
||||
*/
|
||||
protected function getConfig($name)
|
||||
{
|
||||
if (! is_null($name) && $name !== 'null') {
|
||||
return $this->app['config']["queue.connections.{$name}"];
|
||||
}
|
||||
|
||||
return ['driver' => 'null'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the default queue connection.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDefaultDriver()
|
||||
{
|
||||
return $this->app['config']['queue.default'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the name of the default queue connection.
|
||||
*
|
||||
* @param string $name
|
||||
* @return void
|
||||
*/
|
||||
public function setDefaultDriver($name)
|
||||
{
|
||||
$this->app['config']['queue.default'] = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the full name for the given connection.
|
||||
*
|
||||
* @param string|null $connection
|
||||
* @return string
|
||||
*/
|
||||
public function getName($connection = null)
|
||||
{
|
||||
return $connection ?: $this->getDefaultDriver();
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamically pass calls to the default connection.
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call($method, $parameters)
|
||||
{
|
||||
return $this->connection()->$method(...$parameters);
|
||||
}
|
||||
}
|
||||
278
vendor/laravel/framework/src/Illuminate/Queue/QueueServiceProvider.php
vendored
Executable file
278
vendor/laravel/framework/src/Illuminate/Queue/QueueServiceProvider.php
vendored
Executable file
@@ -0,0 +1,278 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Queue;
|
||||
|
||||
use Aws\DynamoDb\DynamoDbClient;
|
||||
use Illuminate\Contracts\Debug\ExceptionHandler;
|
||||
use Illuminate\Contracts\Support\DeferrableProvider;
|
||||
use Illuminate\Queue\Connectors\BeanstalkdConnector;
|
||||
use Illuminate\Queue\Connectors\DatabaseConnector;
|
||||
use Illuminate\Queue\Connectors\NullConnector;
|
||||
use Illuminate\Queue\Connectors\RedisConnector;
|
||||
use Illuminate\Queue\Connectors\SqsConnector;
|
||||
use Illuminate\Queue\Connectors\SyncConnector;
|
||||
use Illuminate\Queue\Failed\DatabaseFailedJobProvider;
|
||||
use Illuminate\Queue\Failed\DynamoDbFailedJobProvider;
|
||||
use Illuminate\Queue\Failed\NullFailedJobProvider;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\Support\Str;
|
||||
use Opis\Closure\SerializableClosure;
|
||||
|
||||
class QueueServiceProvider extends ServiceProvider implements DeferrableProvider
|
||||
{
|
||||
/**
|
||||
* Register the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->registerManager();
|
||||
$this->registerConnection();
|
||||
$this->registerWorker();
|
||||
$this->registerListener();
|
||||
$this->registerFailedJobServices();
|
||||
$this->registerOpisSecurityKey();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the queue manager.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function registerManager()
|
||||
{
|
||||
$this->app->singleton('queue', function ($app) {
|
||||
// Once we have an instance of the queue manager, we will register the various
|
||||
// resolvers for the queue connectors. These connectors are responsible for
|
||||
// creating the classes that accept queue configs and instantiate queues.
|
||||
return tap(new QueueManager($app), function ($manager) {
|
||||
$this->registerConnectors($manager);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the default queue connection binding.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function registerConnection()
|
||||
{
|
||||
$this->app->singleton('queue.connection', function ($app) {
|
||||
return $app['queue']->connection();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the connectors on the queue manager.
|
||||
*
|
||||
* @param \Illuminate\Queue\QueueManager $manager
|
||||
* @return void
|
||||
*/
|
||||
public function registerConnectors($manager)
|
||||
{
|
||||
foreach (['Null', 'Sync', 'Database', 'Redis', 'Beanstalkd', 'Sqs'] as $connector) {
|
||||
$this->{"register{$connector}Connector"}($manager);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the Null queue connector.
|
||||
*
|
||||
* @param \Illuminate\Queue\QueueManager $manager
|
||||
* @return void
|
||||
*/
|
||||
protected function registerNullConnector($manager)
|
||||
{
|
||||
$manager->addConnector('null', function () {
|
||||
return new NullConnector;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the Sync queue connector.
|
||||
*
|
||||
* @param \Illuminate\Queue\QueueManager $manager
|
||||
* @return void
|
||||
*/
|
||||
protected function registerSyncConnector($manager)
|
||||
{
|
||||
$manager->addConnector('sync', function () {
|
||||
return new SyncConnector;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the database queue connector.
|
||||
*
|
||||
* @param \Illuminate\Queue\QueueManager $manager
|
||||
* @return void
|
||||
*/
|
||||
protected function registerDatabaseConnector($manager)
|
||||
{
|
||||
$manager->addConnector('database', function () {
|
||||
return new DatabaseConnector($this->app['db']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the Redis queue connector.
|
||||
*
|
||||
* @param \Illuminate\Queue\QueueManager $manager
|
||||
* @return void
|
||||
*/
|
||||
protected function registerRedisConnector($manager)
|
||||
{
|
||||
$manager->addConnector('redis', function () {
|
||||
return new RedisConnector($this->app['redis']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the Beanstalkd queue connector.
|
||||
*
|
||||
* @param \Illuminate\Queue\QueueManager $manager
|
||||
* @return void
|
||||
*/
|
||||
protected function registerBeanstalkdConnector($manager)
|
||||
{
|
||||
$manager->addConnector('beanstalkd', function () {
|
||||
return new BeanstalkdConnector;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the Amazon SQS queue connector.
|
||||
*
|
||||
* @param \Illuminate\Queue\QueueManager $manager
|
||||
* @return void
|
||||
*/
|
||||
protected function registerSqsConnector($manager)
|
||||
{
|
||||
$manager->addConnector('sqs', function () {
|
||||
return new SqsConnector;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the queue worker.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function registerWorker()
|
||||
{
|
||||
$this->app->singleton('queue.worker', function ($app) {
|
||||
$isDownForMaintenance = function () {
|
||||
return $this->app->isDownForMaintenance();
|
||||
};
|
||||
|
||||
return new Worker(
|
||||
$app['queue'],
|
||||
$app['events'],
|
||||
$app[ExceptionHandler::class],
|
||||
$isDownForMaintenance
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the queue listener.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function registerListener()
|
||||
{
|
||||
$this->app->singleton('queue.listener', function ($app) {
|
||||
return new Listener($app->basePath());
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the failed job services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function registerFailedJobServices()
|
||||
{
|
||||
$this->app->singleton('queue.failer', function ($app) {
|
||||
$config = $app['config']['queue.failed'];
|
||||
|
||||
if (isset($config['driver']) && $config['driver'] === 'dynamodb') {
|
||||
return $this->dynamoFailedJobProvider($config);
|
||||
} elseif (isset($config['table'])) {
|
||||
return $this->databaseFailedJobProvider($config);
|
||||
} else {
|
||||
return new NullFailedJobProvider;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new database failed job provider.
|
||||
*
|
||||
* @param array $config
|
||||
* @return \Illuminate\Queue\Failed\DatabaseFailedJobProvider
|
||||
*/
|
||||
protected function databaseFailedJobProvider($config)
|
||||
{
|
||||
return new DatabaseFailedJobProvider(
|
||||
$this->app['db'], $config['database'], $config['table']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new DynamoDb failed job provider.
|
||||
*
|
||||
* @param array $config
|
||||
* @return \Illuminate\Queue\Failed\DynamoDbFailedJobProvider
|
||||
*/
|
||||
protected function dynamoFailedJobProvider($config)
|
||||
{
|
||||
$dynamoConfig = [
|
||||
'region' => $config['region'],
|
||||
'version' => 'latest',
|
||||
'endpoint' => $config['endpoint'] ?? null,
|
||||
];
|
||||
|
||||
if (! empty($config['key']) && ! empty($config['secret'])) {
|
||||
$dynamoConfig['credentials'] = Arr::only(
|
||||
$config, ['key', 'secret', 'token']
|
||||
);
|
||||
}
|
||||
|
||||
return new DynamoDbFailedJobProvider(
|
||||
new DynamoDbClient($dynamoConfig),
|
||||
$this->app['config']['app.name'],
|
||||
$config['table']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure Opis Closure signing for security.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function registerOpisSecurityKey()
|
||||
{
|
||||
if (Str::startsWith($key = $this->app['config']->get('app.key'), 'base64:')) {
|
||||
$key = base64_decode(substr($key, 7));
|
||||
}
|
||||
|
||||
SerializableClosure::setSecretKey($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the services provided by the provider.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function provides()
|
||||
{
|
||||
return [
|
||||
'queue', 'queue.worker', 'queue.listener',
|
||||
'queue.failer', 'queue.connection',
|
||||
];
|
||||
}
|
||||
}
|
||||
34
vendor/laravel/framework/src/Illuminate/Queue/README.md
vendored
Normal file
34
vendor/laravel/framework/src/Illuminate/Queue/README.md
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
## Illuminate Queue
|
||||
|
||||
The Laravel Queue component provides a unified API across a variety of different queue services. Queues allow you to defer the processing of a time consuming task, such as sending an e-mail, until a later time, thus drastically speeding up the web requests to your application.
|
||||
|
||||
### Usage Instructions
|
||||
|
||||
First, create a new Queue `Capsule` manager instance. Similar to the "Capsule" provided for the Eloquent ORM, the queue Capsule aims to make configuring the library for usage outside of the Laravel framework as easy as possible.
|
||||
|
||||
```PHP
|
||||
use Illuminate\Queue\Capsule\Manager as Queue;
|
||||
|
||||
$queue = new Queue;
|
||||
|
||||
$queue->addConnection([
|
||||
'driver' => 'beanstalkd',
|
||||
'host' => 'localhost',
|
||||
'queue' => 'default',
|
||||
]);
|
||||
|
||||
// Make this Capsule instance available globally via static methods... (optional)
|
||||
$queue->setAsGlobal();
|
||||
```
|
||||
|
||||
Once the Capsule instance has been registered. You may use it like so:
|
||||
|
||||
```PHP
|
||||
// As an instance...
|
||||
$queue->push('SendEmail', ['message' => $message]);
|
||||
|
||||
// If setAsGlobal has been called...
|
||||
Queue::push('SendEmail', ['message' => $message]);
|
||||
```
|
||||
|
||||
For further documentation on using the queue, consult the [Laravel framework documentation](https://laravel.com/docs).
|
||||
310
vendor/laravel/framework/src/Illuminate/Queue/RedisQueue.php
vendored
Normal file
310
vendor/laravel/framework/src/Illuminate/Queue/RedisQueue.php
vendored
Normal file
@@ -0,0 +1,310 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Queue;
|
||||
|
||||
use Illuminate\Contracts\Queue\Queue as QueueContract;
|
||||
use Illuminate\Contracts\Redis\Factory as Redis;
|
||||
use Illuminate\Queue\Jobs\RedisJob;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class RedisQueue extends Queue implements QueueContract
|
||||
{
|
||||
/**
|
||||
* The Redis factory implementation.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Redis\Factory
|
||||
*/
|
||||
protected $redis;
|
||||
|
||||
/**
|
||||
* The connection name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $connection;
|
||||
|
||||
/**
|
||||
* The name of the default queue.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $default;
|
||||
|
||||
/**
|
||||
* The expiration time of a job.
|
||||
*
|
||||
* @var int|null
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Redis\Factory $redis
|
||||
* @param string $default
|
||||
* @param string|null $connection
|
||||
* @param int $retryAfter
|
||||
* @param int|null $blockFor
|
||||
* @return void
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the size of the queue.
|
||||
*
|
||||
* @param string|null $queue
|
||||
* @return int
|
||||
*/
|
||||
public function size($queue = null)
|
||||
{
|
||||
$queue = $this->getQueue($queue);
|
||||
|
||||
return $this->getConnection()->eval(
|
||||
LuaScripts::size(), 3, $queue, $queue.':delayed', $queue.':reserved'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Push a new job onto the queue.
|
||||
*
|
||||
* @param object|string $job
|
||||
* @param mixed $data
|
||||
* @param string|null $queue
|
||||
* @return mixed
|
||||
*/
|
||||
public function push($job, $data = '', $queue = null)
|
||||
{
|
||||
return $this->pushRaw($this->createPayload($job, $this->getQueue($queue), $data), $queue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Push a raw payload onto the queue.
|
||||
*
|
||||
* @param string $payload
|
||||
* @param string|null $queue
|
||||
* @param array $options
|
||||
* @return mixed
|
||||
*/
|
||||
public function pushRaw($payload, $queue = null, array $options = [])
|
||||
{
|
||||
$this->getConnection()->eval(
|
||||
LuaScripts::push(), 2, $this->getQueue($queue),
|
||||
$this->getQueue($queue).':notify', $payload
|
||||
);
|
||||
|
||||
return json_decode($payload, true)['id'] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Push a new job onto the queue after a delay.
|
||||
*
|
||||
* @param \DateTimeInterface|\DateInterval|int $delay
|
||||
* @param object|string $job
|
||||
* @param mixed $data
|
||||
* @param string|null $queue
|
||||
* @return mixed
|
||||
*/
|
||||
public function later($delay, $job, $data = '', $queue = null)
|
||||
{
|
||||
return $this->laterRaw($delay, $this->createPayload($job, $this->getQueue($queue), $data), $queue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Push a raw job onto the queue after a delay.
|
||||
*
|
||||
* @param \DateTimeInterface|\DateInterval|int $delay
|
||||
* @param string $payload
|
||||
* @param string|null $queue
|
||||
* @return mixed
|
||||
*/
|
||||
protected function laterRaw($delay, $payload, $queue = null)
|
||||
{
|
||||
$this->getConnection()->zadd(
|
||||
$this->getQueue($queue).':delayed', $this->availableAt($delay), $payload
|
||||
);
|
||||
|
||||
return json_decode($payload, true)['id'] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a payload string from the given job and data.
|
||||
*
|
||||
* @param string $job
|
||||
* @param string $queue
|
||||
* @param mixed $data
|
||||
* @return array
|
||||
*/
|
||||
protected function createPayloadArray($job, $queue, $data = '')
|
||||
{
|
||||
return array_merge(parent::createPayloadArray($job, $queue, $data), [
|
||||
'id' => $this->getRandomId(),
|
||||
'attempts' => 0,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pop the next job off of the queue.
|
||||
*
|
||||
* @param string|null $queue
|
||||
* @return \Illuminate\Contracts\Queue\Job|null
|
||||
*/
|
||||
public function pop($queue = null)
|
||||
{
|
||||
$this->migrate($prefixed = $this->getQueue($queue));
|
||||
|
||||
if (empty($nextJob = $this->retrieveNextJob($prefixed))) {
|
||||
return;
|
||||
}
|
||||
|
||||
[$job, $reserved] = $nextJob;
|
||||
|
||||
if ($reserved) {
|
||||
return new RedisJob(
|
||||
$this->container, $this, $job,
|
||||
$reserved, $this->connectionName, $queue ?: $this->default
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Migrate any delayed or expired jobs onto the primary queue.
|
||||
*
|
||||
* @param string $queue
|
||||
* @return void
|
||||
*/
|
||||
protected function migrate($queue)
|
||||
{
|
||||
$this->migrateExpiredJobs($queue.':delayed', $queue);
|
||||
|
||||
if (! is_null($this->retryAfter)) {
|
||||
$this->migrateExpiredJobs($queue.':reserved', $queue);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Migrate the delayed jobs that are ready to the regular queue.
|
||||
*
|
||||
* @param string $from
|
||||
* @param string $to
|
||||
* @return array
|
||||
*/
|
||||
public function migrateExpiredJobs($from, $to)
|
||||
{
|
||||
return $this->getConnection()->eval(
|
||||
LuaScripts::migrateExpiredJobs(), 3, $from, $to, $to.':notify', $this->currentTime()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the next job from the queue.
|
||||
*
|
||||
* @param string $queue
|
||||
* @param bool $block
|
||||
* @return array
|
||||
*/
|
||||
protected function retrieveNextJob($queue, $block = true)
|
||||
{
|
||||
$nextJob = $this->getConnection()->eval(
|
||||
LuaScripts::pop(), 3, $queue, $queue.':reserved', $queue.':notify',
|
||||
$this->availableAt($this->retryAfter)
|
||||
);
|
||||
|
||||
if (empty($nextJob)) {
|
||||
return [null, null];
|
||||
}
|
||||
|
||||
[$job, $reserved] = $nextJob;
|
||||
|
||||
if (! $job && ! is_null($this->blockFor) && $block &&
|
||||
$this->getConnection()->blpop([$queue.':notify'], $this->blockFor)) {
|
||||
return $this->retrieveNextJob($queue, false);
|
||||
}
|
||||
|
||||
return [$job, $reserved];
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a reserved job from the queue.
|
||||
*
|
||||
* @param string $queue
|
||||
* @param \Illuminate\Queue\Jobs\RedisJob $job
|
||||
* @return void
|
||||
*/
|
||||
public function deleteReserved($queue, $job)
|
||||
{
|
||||
$this->getConnection()->zrem($this->getQueue($queue).':reserved', $job->getReservedJob());
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a reserved job from the reserved queue and release it.
|
||||
*
|
||||
* @param string $queue
|
||||
* @param \Illuminate\Queue\Jobs\RedisJob $job
|
||||
* @param int $delay
|
||||
* @return void
|
||||
*/
|
||||
public function deleteAndRelease($queue, $job, $delay)
|
||||
{
|
||||
$queue = $this->getQueue($queue);
|
||||
|
||||
$this->getConnection()->eval(
|
||||
LuaScripts::release(), 2, $queue.':delayed', $queue.':reserved',
|
||||
$job->getReservedJob(), $this->availableAt($delay)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a random ID string.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getRandomId()
|
||||
{
|
||||
return Str::random(32);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the queue or return the default.
|
||||
*
|
||||
* @param string|null $queue
|
||||
* @return string
|
||||
*/
|
||||
public function getQueue($queue)
|
||||
{
|
||||
return 'queues:'.($queue ?: $this->default);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the connection for the queue.
|
||||
*
|
||||
* @return \Illuminate\Redis\Connections\Connection
|
||||
*/
|
||||
public function getConnection()
|
||||
{
|
||||
return $this->redis->connection($this->connection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying Redis instance.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Redis\Factory
|
||||
*/
|
||||
public function getRedis()
|
||||
{
|
||||
return $this->redis;
|
||||
}
|
||||
}
|
||||
40
vendor/laravel/framework/src/Illuminate/Queue/SerializableClosure.php
vendored
Normal file
40
vendor/laravel/framework/src/Illuminate/Queue/SerializableClosure.php
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Queue;
|
||||
|
||||
use Opis\Closure\SerializableClosure as OpisSerializableClosure;
|
||||
|
||||
class SerializableClosure extends OpisSerializableClosure
|
||||
{
|
||||
use SerializesAndRestoresModelIdentifiers;
|
||||
|
||||
/**
|
||||
* Transform the use variables before serialization.
|
||||
*
|
||||
* @param array $data The Closure's use variables
|
||||
* @return array
|
||||
*/
|
||||
protected function transformUseVariables($data)
|
||||
{
|
||||
foreach ($data as $key => $value) {
|
||||
$data[$key] = $this->getSerializedPropertyValue($value);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the use variables after unserialization.
|
||||
*
|
||||
* @param array $data The Closure's transformed use variables
|
||||
* @return array
|
||||
*/
|
||||
protected function resolveUseVariables($data)
|
||||
{
|
||||
foreach ($data as $key => $value) {
|
||||
$data[$key] = $this->getRestoredPropertyValue($value);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
116
vendor/laravel/framework/src/Illuminate/Queue/SerializesAndRestoresModelIdentifiers.php
vendored
Normal file
116
vendor/laravel/framework/src/Illuminate/Queue/SerializesAndRestoresModelIdentifiers.php
vendored
Normal file
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Queue;
|
||||
|
||||
use Illuminate\Contracts\Database\ModelIdentifier;
|
||||
use Illuminate\Contracts\Queue\QueueableCollection;
|
||||
use Illuminate\Contracts\Queue\QueueableEntity;
|
||||
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
|
||||
use Illuminate\Database\Eloquent\Relations\Concerns\AsPivot;
|
||||
use Illuminate\Database\Eloquent\Relations\Pivot;
|
||||
|
||||
trait SerializesAndRestoresModelIdentifiers
|
||||
{
|
||||
/**
|
||||
* Get the property value prepared for serialization.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getSerializedPropertyValue($value)
|
||||
{
|
||||
if ($value instanceof QueueableCollection) {
|
||||
return new ModelIdentifier(
|
||||
$value->getQueueableClass(),
|
||||
$value->getQueueableIds(),
|
||||
$value->getQueueableRelations(),
|
||||
$value->getQueueableConnection()
|
||||
);
|
||||
}
|
||||
|
||||
if ($value instanceof QueueableEntity) {
|
||||
return new ModelIdentifier(
|
||||
get_class($value),
|
||||
$value->getQueueableId(),
|
||||
$value->getQueueableRelations(),
|
||||
$value->getQueueableConnection()
|
||||
);
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the restored property value after deserialization.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getRestoredPropertyValue($value)
|
||||
{
|
||||
if (! $value instanceof ModelIdentifier) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
return is_array($value->id)
|
||||
? $this->restoreCollection($value)
|
||||
: $this->restoreModel($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore a queueable collection instance.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Database\ModelIdentifier $value
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
protected function restoreCollection($value)
|
||||
{
|
||||
if (! $value->class || count($value->id) === 0) {
|
||||
return new EloquentCollection;
|
||||
}
|
||||
|
||||
$collection = $this->getQueryForModelRestoration(
|
||||
(new $value->class)->setConnection($value->connection), $value->id
|
||||
)->useWritePdo()->get();
|
||||
|
||||
if (is_a($value->class, Pivot::class, true) ||
|
||||
in_array(AsPivot::class, class_uses($value->class))) {
|
||||
return $collection;
|
||||
}
|
||||
|
||||
$collection = $collection->keyBy->getKey();
|
||||
|
||||
$collectionClass = get_class($collection);
|
||||
|
||||
return new $collectionClass(
|
||||
collect($value->id)->map(function ($id) use ($collection) {
|
||||
return $collection[$id] ?? null;
|
||||
})->filter()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
protected function getQueryForModelRestoration($model, $ids)
|
||||
{
|
||||
return $model->newQueryForRestoration($ids);
|
||||
}
|
||||
}
|
||||
141
vendor/laravel/framework/src/Illuminate/Queue/SerializesModels.php
vendored
Normal file
141
vendor/laravel/framework/src/Illuminate/Queue/SerializesModels.php
vendored
Normal file
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Queue;
|
||||
|
||||
use ReflectionClass;
|
||||
use ReflectionProperty;
|
||||
|
||||
trait SerializesModels
|
||||
{
|
||||
use SerializesAndRestoresModelIdentifiers;
|
||||
|
||||
/**
|
||||
* Prepare the instance for serialization.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function __sleep()
|
||||
{
|
||||
$properties = (new ReflectionClass($this))->getProperties();
|
||||
|
||||
foreach ($properties as $property) {
|
||||
$property->setValue($this, $this->getSerializedPropertyValue(
|
||||
$this->getPropertyValue($property)
|
||||
));
|
||||
}
|
||||
|
||||
return array_values(array_filter(array_map(function ($p) {
|
||||
return $p->isStatic() ? null : $p->getName();
|
||||
}, $properties)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore the model after serialization.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __wakeup()
|
||||
{
|
||||
foreach ((new ReflectionClass($this))->getProperties() as $property) {
|
||||
if ($property->isStatic()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$property->setValue($this, $this->getRestoredPropertyValue(
|
||||
$this->getPropertyValue($property)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the instance values for serialization.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function __serialize()
|
||||
{
|
||||
$values = [];
|
||||
|
||||
$properties = (new ReflectionClass($this))->getProperties();
|
||||
|
||||
$class = get_class($this);
|
||||
|
||||
foreach ($properties as $property) {
|
||||
if ($property->isStatic()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$property->setAccessible(true);
|
||||
|
||||
if (! $property->isInitialized($this)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$name = $property->getName();
|
||||
|
||||
if ($property->isPrivate()) {
|
||||
$name = "\0{$class}\0{$name}";
|
||||
} elseif ($property->isProtected()) {
|
||||
$name = "\0*\0{$name}";
|
||||
}
|
||||
|
||||
$values[$name] = $this->getSerializedPropertyValue(
|
||||
$this->getPropertyValue($property)
|
||||
);
|
||||
}
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore the model after serialization.
|
||||
*
|
||||
* @param array $values
|
||||
* @return array
|
||||
*/
|
||||
public function __unserialize(array $values)
|
||||
{
|
||||
$properties = (new ReflectionClass($this))->getProperties();
|
||||
|
||||
$class = get_class($this);
|
||||
|
||||
foreach ($properties as $property) {
|
||||
if ($property->isStatic()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$name = $property->getName();
|
||||
|
||||
if ($property->isPrivate()) {
|
||||
$name = "\0{$class}\0{$name}";
|
||||
} elseif ($property->isProtected()) {
|
||||
$name = "\0*\0{$name}";
|
||||
}
|
||||
|
||||
if (! array_key_exists($name, $values)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$property->setAccessible(true);
|
||||
|
||||
$property->setValue(
|
||||
$this, $this->getRestoredPropertyValue($values[$name])
|
||||
);
|
||||
}
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the property value for the given property.
|
||||
*
|
||||
* @param \ReflectionProperty $property
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getPropertyValue(ReflectionProperty $property)
|
||||
{
|
||||
$property->setAccessible(true);
|
||||
|
||||
return $property->getValue($this);
|
||||
}
|
||||
}
|
||||
166
vendor/laravel/framework/src/Illuminate/Queue/SqsQueue.php
vendored
Executable file
166
vendor/laravel/framework/src/Illuminate/Queue/SqsQueue.php
vendored
Executable file
@@ -0,0 +1,166 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Queue;
|
||||
|
||||
use Aws\Sqs\SqsClient;
|
||||
use Illuminate\Contracts\Queue\Queue as QueueContract;
|
||||
use Illuminate\Queue\Jobs\SqsJob;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class SqsQueue extends Queue implements QueueContract
|
||||
{
|
||||
/**
|
||||
* The Amazon SQS instance.
|
||||
*
|
||||
* @var \Aws\Sqs\SqsClient
|
||||
*/
|
||||
protected $sqs;
|
||||
|
||||
/**
|
||||
* The name of the default queue.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $default;
|
||||
|
||||
/**
|
||||
* The queue URL prefix.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $prefix;
|
||||
|
||||
/**
|
||||
* The queue name suffix.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $suffix;
|
||||
|
||||
/**
|
||||
* Create a new Amazon SQS queue instance.
|
||||
*
|
||||
* @param \Aws\Sqs\SqsClient $sqs
|
||||
* @param string $default
|
||||
* @param string $prefix
|
||||
* @param string $suffix
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(SqsClient $sqs, $default, $prefix = '', $suffix = '')
|
||||
{
|
||||
$this->sqs = $sqs;
|
||||
$this->prefix = $prefix;
|
||||
$this->default = $default;
|
||||
$this->suffix = $suffix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the size of the queue.
|
||||
*
|
||||
* @param string|null $queue
|
||||
* @return int
|
||||
*/
|
||||
public function size($queue = null)
|
||||
{
|
||||
$response = $this->sqs->getQueueAttributes([
|
||||
'QueueUrl' => $this->getQueue($queue),
|
||||
'AttributeNames' => ['ApproximateNumberOfMessages'],
|
||||
]);
|
||||
|
||||
$attributes = $response->get('Attributes');
|
||||
|
||||
return (int) $attributes['ApproximateNumberOfMessages'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Push a new job onto the queue.
|
||||
*
|
||||
* @param string $job
|
||||
* @param mixed $data
|
||||
* @param string|null $queue
|
||||
* @return mixed
|
||||
*/
|
||||
public function push($job, $data = '', $queue = null)
|
||||
{
|
||||
return $this->pushRaw($this->createPayload($job, $queue ?: $this->default, $data), $queue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Push a raw payload onto the queue.
|
||||
*
|
||||
* @param string $payload
|
||||
* @param string|null $queue
|
||||
* @param array $options
|
||||
* @return mixed
|
||||
*/
|
||||
public function pushRaw($payload, $queue = null, array $options = [])
|
||||
{
|
||||
return $this->sqs->sendMessage([
|
||||
'QueueUrl' => $this->getQueue($queue), 'MessageBody' => $payload,
|
||||
])->get('MessageId');
|
||||
}
|
||||
|
||||
/**
|
||||
* Push a new job onto the queue after a delay.
|
||||
*
|
||||
* @param \DateTimeInterface|\DateInterval|int $delay
|
||||
* @param string $job
|
||||
* @param mixed $data
|
||||
* @param string|null $queue
|
||||
* @return mixed
|
||||
*/
|
||||
public function later($delay, $job, $data = '', $queue = null)
|
||||
{
|
||||
return $this->sqs->sendMessage([
|
||||
'QueueUrl' => $this->getQueue($queue),
|
||||
'MessageBody' => $this->createPayload($job, $queue ?: $this->default, $data),
|
||||
'DelaySeconds' => $this->secondsUntil($delay),
|
||||
])->get('MessageId');
|
||||
}
|
||||
|
||||
/**
|
||||
* Pop the next job off of the queue.
|
||||
*
|
||||
* @param string|null $queue
|
||||
* @return \Illuminate\Contracts\Queue\Job|null
|
||||
*/
|
||||
public function pop($queue = null)
|
||||
{
|
||||
$response = $this->sqs->receiveMessage([
|
||||
'QueueUrl' => $queue = $this->getQueue($queue),
|
||||
'AttributeNames' => ['ApproximateReceiveCount'],
|
||||
]);
|
||||
|
||||
if (! is_null($response['Messages']) && count($response['Messages']) > 0) {
|
||||
return new SqsJob(
|
||||
$this->container, $this->sqs, $response['Messages'][0],
|
||||
$this->connectionName, $queue
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the queue or return the default.
|
||||
*
|
||||
* @param string|null $queue
|
||||
* @return string
|
||||
*/
|
||||
public function getQueue($queue)
|
||||
{
|
||||
$queue = $queue ?: $this->default;
|
||||
|
||||
return filter_var($queue, FILTER_VALIDATE_URL) === false
|
||||
? rtrim($this->prefix, '/').'/'.Str::finish($queue, $this->suffix)
|
||||
: $queue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying SQS instance.
|
||||
*
|
||||
* @return \Aws\Sqs\SqsClient
|
||||
*/
|
||||
public function getSqs()
|
||||
{
|
||||
return $this->sqs;
|
||||
}
|
||||
}
|
||||
160
vendor/laravel/framework/src/Illuminate/Queue/SyncQueue.php
vendored
Executable file
160
vendor/laravel/framework/src/Illuminate/Queue/SyncQueue.php
vendored
Executable file
@@ -0,0 +1,160 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Queue;
|
||||
|
||||
use Illuminate\Contracts\Queue\Job;
|
||||
use Illuminate\Contracts\Queue\Queue as QueueContract;
|
||||
use Illuminate\Queue\Events\JobExceptionOccurred;
|
||||
use Illuminate\Queue\Events\JobProcessed;
|
||||
use Illuminate\Queue\Events\JobProcessing;
|
||||
use Illuminate\Queue\Jobs\SyncJob;
|
||||
use Throwable;
|
||||
|
||||
class SyncQueue extends Queue implements QueueContract
|
||||
{
|
||||
/**
|
||||
* Get the size of the queue.
|
||||
*
|
||||
* @param string|null $queue
|
||||
* @return int
|
||||
*/
|
||||
public function size($queue = null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Push a new job onto the queue.
|
||||
*
|
||||
* @param string $job
|
||||
* @param mixed $data
|
||||
* @param string|null $queue
|
||||
* @return mixed
|
||||
*
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function push($job, $data = '', $queue = null)
|
||||
{
|
||||
$queueJob = $this->resolveJob($this->createPayload($job, $queue, $data), $queue);
|
||||
|
||||
try {
|
||||
$this->raiseBeforeJobEvent($queueJob);
|
||||
|
||||
$queueJob->fire();
|
||||
|
||||
$this->raiseAfterJobEvent($queueJob);
|
||||
} catch (Throwable $e) {
|
||||
$this->handleException($queueJob, $e);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve a Sync job instance.
|
||||
*
|
||||
* @param string $payload
|
||||
* @param string $queue
|
||||
* @return \Illuminate\Queue\Jobs\SyncJob
|
||||
*/
|
||||
protected function resolveJob($payload, $queue)
|
||||
{
|
||||
return new SyncJob($this->container, $payload, $this->connectionName, $queue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Raise the before queue job event.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Queue\Job $job
|
||||
* @return void
|
||||
*/
|
||||
protected function raiseBeforeJobEvent(Job $job)
|
||||
{
|
||||
if ($this->container->bound('events')) {
|
||||
$this->container['events']->dispatch(new JobProcessing($this->connectionName, $job));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Raise the after queue job event.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Queue\Job $job
|
||||
* @return void
|
||||
*/
|
||||
protected function raiseAfterJobEvent(Job $job)
|
||||
{
|
||||
if ($this->container->bound('events')) {
|
||||
$this->container['events']->dispatch(new JobProcessed($this->connectionName, $job));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Raise the exception occurred queue job event.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Queue\Job $job
|
||||
* @param \Throwable $e
|
||||
* @return void
|
||||
*/
|
||||
protected function raiseExceptionOccurredJobEvent(Job $job, Throwable $e)
|
||||
{
|
||||
if ($this->container->bound('events')) {
|
||||
$this->container['events']->dispatch(new JobExceptionOccurred($this->connectionName, $job, $e));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an exception that occurred while processing a job.
|
||||
*
|
||||
* @param \Illuminate\Queue\Jobs\Job $queueJob
|
||||
* @param \Throwable $e
|
||||
* @return void
|
||||
*
|
||||
* @throws \Throwable
|
||||
*/
|
||||
protected function handleException(Job $queueJob, Throwable $e)
|
||||
{
|
||||
$this->raiseExceptionOccurredJobEvent($queueJob, $e);
|
||||
|
||||
$queueJob->fail($e);
|
||||
|
||||
throw $e;
|
||||
}
|
||||
|
||||
/**
|
||||
* Push a raw payload onto the queue.
|
||||
*
|
||||
* @param string $payload
|
||||
* @param string|null $queue
|
||||
* @param array $options
|
||||
* @return mixed
|
||||
*/
|
||||
public function pushRaw($payload, $queue = null, array $options = [])
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Push a new job onto the queue after a delay.
|
||||
*
|
||||
* @param \DateTimeInterface|\DateInterval|int $delay
|
||||
* @param string $job
|
||||
* @param mixed $data
|
||||
* @param string|null $queue
|
||||
* @return mixed
|
||||
*/
|
||||
public function later($delay, $job, $data = '', $queue = null)
|
||||
{
|
||||
return $this->push($job, $data, $queue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pop the next job off of the queue.
|
||||
*
|
||||
* @param string|null $queue
|
||||
* @return \Illuminate\Contracts\Queue\Job|null
|
||||
*/
|
||||
public function pop($queue = null)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
699
vendor/laravel/framework/src/Illuminate/Queue/Worker.php
vendored
Normal file
699
vendor/laravel/framework/src/Illuminate/Queue/Worker.php
vendored
Normal file
@@ -0,0 +1,699 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Queue;
|
||||
|
||||
use Illuminate\Contracts\Cache\Repository as CacheContract;
|
||||
use Illuminate\Contracts\Debug\ExceptionHandler;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
use Illuminate\Contracts\Queue\Factory as QueueManager;
|
||||
use Illuminate\Database\DetectsLostConnections;
|
||||
use Illuminate\Queue\Events\JobExceptionOccurred;
|
||||
use Illuminate\Queue\Events\JobProcessed;
|
||||
use Illuminate\Queue\Events\JobProcessing;
|
||||
use Illuminate\Queue\Events\Looping;
|
||||
use Illuminate\Queue\Events\WorkerStopping;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Throwable;
|
||||
|
||||
class Worker
|
||||
{
|
||||
use DetectsLostConnections;
|
||||
|
||||
/**
|
||||
* The queue manager instance.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Queue\Factory
|
||||
*/
|
||||
protected $manager;
|
||||
|
||||
/**
|
||||
* The event dispatcher instance.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Events\Dispatcher
|
||||
*/
|
||||
protected $events;
|
||||
|
||||
/**
|
||||
* The cache repository implementation.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Cache\Repository
|
||||
*/
|
||||
protected $cache;
|
||||
|
||||
/**
|
||||
* The exception handler instance.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Debug\ExceptionHandler
|
||||
*/
|
||||
protected $exceptions;
|
||||
|
||||
/**
|
||||
* The callback used to determine if the application is in maintenance mode.
|
||||
*
|
||||
* @var callable
|
||||
*/
|
||||
protected $isDownForMaintenance;
|
||||
|
||||
/**
|
||||
* Indicates if the worker should exit.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $shouldQuit = false;
|
||||
|
||||
/**
|
||||
* Indicates if the worker is paused.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $paused = false;
|
||||
|
||||
/**
|
||||
* Create a new queue worker.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Queue\Factory $manager
|
||||
* @param \Illuminate\Contracts\Events\Dispatcher $events
|
||||
* @param \Illuminate\Contracts\Debug\ExceptionHandler $exceptions
|
||||
* @param callable $isDownForMaintenance
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(QueueManager $manager,
|
||||
Dispatcher $events,
|
||||
ExceptionHandler $exceptions,
|
||||
callable $isDownForMaintenance)
|
||||
{
|
||||
$this->events = $events;
|
||||
$this->manager = $manager;
|
||||
$this->exceptions = $exceptions;
|
||||
$this->isDownForMaintenance = $isDownForMaintenance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Listen to the given queue in a loop.
|
||||
*
|
||||
* @param string $connectionName
|
||||
* @param string $queue
|
||||
* @param \Illuminate\Queue\WorkerOptions $options
|
||||
* @return void
|
||||
*/
|
||||
public function daemon($connectionName, $queue, WorkerOptions $options)
|
||||
{
|
||||
if ($this->supportsAsyncSignals()) {
|
||||
$this->listenForSignals();
|
||||
}
|
||||
|
||||
$lastRestart = $this->getTimestampOfLastQueueRestart();
|
||||
|
||||
while (true) {
|
||||
// Before reserving any jobs, we will make sure this queue is not paused and
|
||||
// if it is we will just pause this worker for a given amount of time and
|
||||
// make sure we do not need to kill this worker process off completely.
|
||||
if (! $this->daemonShouldRun($options, $connectionName, $queue)) {
|
||||
$this->pauseWorker($options, $lastRestart);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// First, we will attempt to get the next job off of the queue. We will also
|
||||
// register the timeout handler and reset the alarm for this job so it is
|
||||
// not stuck in a frozen state forever. Then, we can fire off this job.
|
||||
$job = $this->getNextJob(
|
||||
$this->manager->connection($connectionName), $queue
|
||||
);
|
||||
|
||||
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
|
||||
// worker so no more jobs are processed until they should be processed.
|
||||
if ($job) {
|
||||
$this->runJob($job, $connectionName, $options);
|
||||
} else {
|
||||
$this->sleep($options->sleep);
|
||||
}
|
||||
|
||||
if ($this->supportsAsyncSignals()) {
|
||||
$this->resetTimeoutHandler();
|
||||
}
|
||||
|
||||
// Finally, we will check to see if we have exceeded our memory limits or if
|
||||
// the queue should restart based on other indications. If so, we'll stop
|
||||
// this worker and let whatever is "monitoring" it restart the process.
|
||||
$this->stopIfNecessary($options, $lastRestart, $job);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the worker timeout handler.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Queue\Job|null $job
|
||||
* @param \Illuminate\Queue\WorkerOptions $options
|
||||
* @return void
|
||||
*/
|
||||
protected function registerTimeoutHandler($job, WorkerOptions $options)
|
||||
{
|
||||
// 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 () use ($job, $options) {
|
||||
if ($job) {
|
||||
$this->markJobAsFailedIfWillExceedMaxAttempts(
|
||||
$job->getConnectionName(), $job, (int) $options->maxTries, $this->maxAttemptsExceededException($job)
|
||||
);
|
||||
}
|
||||
|
||||
$this->kill(1);
|
||||
});
|
||||
|
||||
pcntl_alarm(
|
||||
max($this->timeoutForJob($job, $options), 0)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the worker timeout handler.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function resetTimeoutHandler()
|
||||
{
|
||||
pcntl_alarm(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the appropriate timeout for the given job.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Queue\Job|null $job
|
||||
* @param \Illuminate\Queue\WorkerOptions $options
|
||||
* @return int
|
||||
*/
|
||||
protected function timeoutForJob($job, WorkerOptions $options)
|
||||
{
|
||||
return $job && ! is_null($job->timeout()) ? $job->timeout() : $options->timeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the daemon should process on this iteration.
|
||||
*
|
||||
* @param \Illuminate\Queue\WorkerOptions $options
|
||||
* @param string $connectionName
|
||||
* @param string $queue
|
||||
* @return bool
|
||||
*/
|
||||
protected function daemonShouldRun(WorkerOptions $options, $connectionName, $queue)
|
||||
{
|
||||
return ! ((($this->isDownForMaintenance)() && ! $options->force) ||
|
||||
$this->paused ||
|
||||
$this->events->until(new Looping($connectionName, $queue)) === false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pause the worker for the current loop.
|
||||
*
|
||||
* @param \Illuminate\Queue\WorkerOptions $options
|
||||
* @param int $lastRestart
|
||||
* @return void
|
||||
*/
|
||||
protected function pauseWorker(WorkerOptions $options, $lastRestart)
|
||||
{
|
||||
$this->sleep($options->sleep > 0 ? $options->sleep : 1);
|
||||
|
||||
$this->stopIfNecessary($options, $lastRestart);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop the process if necessary.
|
||||
*
|
||||
* @param \Illuminate\Queue\WorkerOptions $options
|
||||
* @param int $lastRestart
|
||||
* @param mixed $job
|
||||
* @return void
|
||||
*/
|
||||
protected function stopIfNecessary(WorkerOptions $options, $lastRestart, $job = null)
|
||||
{
|
||||
if ($this->shouldQuit) {
|
||||
$this->stop();
|
||||
} elseif ($this->memoryExceeded($options->memory)) {
|
||||
$this->stop(12);
|
||||
} elseif ($this->queueShouldRestart($lastRestart)) {
|
||||
$this->stop();
|
||||
} elseif ($options->stopWhenEmpty && is_null($job)) {
|
||||
$this->stop();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the next job on the queue.
|
||||
*
|
||||
* @param string $connectionName
|
||||
* @param string $queue
|
||||
* @param \Illuminate\Queue\WorkerOptions $options
|
||||
* @return void
|
||||
*/
|
||||
public function runNextJob($connectionName, $queue, WorkerOptions $options)
|
||||
{
|
||||
$job = $this->getNextJob(
|
||||
$this->manager->connection($connectionName), $queue
|
||||
);
|
||||
|
||||
// If we're able to pull a job off of the stack, we will process it and then return
|
||||
// from this method. If there is no job on the queue, we will "sleep" the worker
|
||||
// for the specified number of seconds, then keep processing jobs after sleep.
|
||||
if ($job) {
|
||||
return $this->runJob($job, $connectionName, $options);
|
||||
}
|
||||
|
||||
$this->sleep($options->sleep);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the next job from the queue connection.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Queue\Queue $connection
|
||||
* @param string $queue
|
||||
* @return \Illuminate\Contracts\Queue\Job|null
|
||||
*/
|
||||
protected function getNextJob($connection, $queue)
|
||||
{
|
||||
try {
|
||||
foreach (explode(',', $queue) as $queue) {
|
||||
if (! is_null($job = $connection->pop($queue))) {
|
||||
return $job;
|
||||
}
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
$this->exceptions->report($e);
|
||||
|
||||
$this->stopWorkerIfLostConnection($e);
|
||||
|
||||
$this->sleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the given job.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Queue\Job $job
|
||||
* @param string $connectionName
|
||||
* @param \Illuminate\Queue\WorkerOptions $options
|
||||
* @return void
|
||||
*/
|
||||
protected function runJob($job, $connectionName, WorkerOptions $options)
|
||||
{
|
||||
try {
|
||||
return $this->process($connectionName, $job, $options);
|
||||
} catch (Throwable $e) {
|
||||
$this->exceptions->report($e);
|
||||
|
||||
$this->stopWorkerIfLostConnection($e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop the worker if we have lost connection to a database.
|
||||
*
|
||||
* @param \Throwable $e
|
||||
* @return void
|
||||
*/
|
||||
protected function stopWorkerIfLostConnection($e)
|
||||
{
|
||||
if ($this->causedByLostConnection($e)) {
|
||||
$this->shouldQuit = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the given job from the queue.
|
||||
*
|
||||
* @param string $connectionName
|
||||
* @param \Illuminate\Contracts\Queue\Job $job
|
||||
* @param \Illuminate\Queue\WorkerOptions $options
|
||||
* @return void
|
||||
*
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function process($connectionName, $job, WorkerOptions $options)
|
||||
{
|
||||
try {
|
||||
// First we will raise the before job event and determine if the job has already ran
|
||||
// over its maximum attempt limits, which could primarily happen when this job is
|
||||
// continually timing out and not actually throwing any exceptions from itself.
|
||||
$this->raiseBeforeJobEvent($connectionName, $job);
|
||||
|
||||
$this->markJobAsFailedIfAlreadyExceedsMaxAttempts(
|
||||
$connectionName, $job, (int) $options->maxTries
|
||||
);
|
||||
|
||||
if ($job->isDeleted()) {
|
||||
return $this->raiseAfterJobEvent($connectionName, $job);
|
||||
}
|
||||
|
||||
// Here we will fire off the job and let it process. We will catch any exceptions so
|
||||
// they can be reported to the developers logs, etc. Once the job is finished the
|
||||
// proper events will be fired to let any listeners know this job has finished.
|
||||
$job->fire();
|
||||
|
||||
$this->raiseAfterJobEvent($connectionName, $job);
|
||||
} catch (Throwable $e) {
|
||||
$this->handleJobException($connectionName, $job, $options, $e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an exception that occurred while the job was running.
|
||||
*
|
||||
* @param string $connectionName
|
||||
* @param \Illuminate\Contracts\Queue\Job $job
|
||||
* @param \Illuminate\Queue\WorkerOptions $options
|
||||
* @param \Throwable $e
|
||||
* @return void
|
||||
*
|
||||
* @throws \Throwable
|
||||
*/
|
||||
protected function handleJobException($connectionName, $job, WorkerOptions $options, Throwable $e)
|
||||
{
|
||||
try {
|
||||
// First, we will go ahead and mark the job as failed if it will exceed the maximum
|
||||
// attempts it is allowed to run the next time we process it. If so we will just
|
||||
// go ahead and mark it as failed now so we do not have to release this again.
|
||||
if (! $job->hasFailed()) {
|
||||
$this->markJobAsFailedIfWillExceedMaxAttempts(
|
||||
$connectionName, $job, (int) $options->maxTries, $e
|
||||
);
|
||||
|
||||
$this->markJobAsFailedIfWillExceedMaxExceptions(
|
||||
$connectionName, $job, $e
|
||||
);
|
||||
}
|
||||
|
||||
$this->raiseExceptionOccurredJobEvent(
|
||||
$connectionName, $job, $e
|
||||
);
|
||||
} finally {
|
||||
// If we catch an exception, we will attempt to release the job back onto the queue
|
||||
// so it is not lost entirely. This'll let the job be retried at a later time by
|
||||
// another listener (or this same one). We will re-throw this exception after.
|
||||
if (! $job->isDeleted() && ! $job->isReleased() && ! $job->hasFailed()) {
|
||||
$job->release(
|
||||
method_exists($job, 'delaySeconds') && ! is_null($job->delaySeconds())
|
||||
? $job->delaySeconds()
|
||||
: $options->delay
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
throw $e;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark the given job as failed if it has exceeded the maximum allowed attempts.
|
||||
*
|
||||
* This will likely be because the job previously exceeded a timeout.
|
||||
*
|
||||
* @param string $connectionName
|
||||
* @param \Illuminate\Contracts\Queue\Job $job
|
||||
* @param int $maxTries
|
||||
* @return void
|
||||
*
|
||||
* @throws \Throwable
|
||||
*/
|
||||
protected function markJobAsFailedIfAlreadyExceedsMaxAttempts($connectionName, $job, $maxTries)
|
||||
{
|
||||
$maxTries = ! is_null($job->maxTries()) ? $job->maxTries() : $maxTries;
|
||||
|
||||
$timeoutAt = $job->timeoutAt();
|
||||
|
||||
if ($timeoutAt && Carbon::now()->getTimestamp() <= $timeoutAt) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (! $timeoutAt && ($maxTries === 0 || $job->attempts() <= $maxTries)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->failJob($job, $e = $this->maxAttemptsExceededException($job));
|
||||
|
||||
throw $e;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark the given job as failed if it has exceeded the maximum allowed attempts.
|
||||
*
|
||||
* @param string $connectionName
|
||||
* @param \Illuminate\Contracts\Queue\Job $job
|
||||
* @param int $maxTries
|
||||
* @param \Throwable $e
|
||||
* @return void
|
||||
*/
|
||||
protected function markJobAsFailedIfWillExceedMaxAttempts($connectionName, $job, $maxTries, Throwable $e)
|
||||
{
|
||||
$maxTries = ! is_null($job->maxTries()) ? $job->maxTries() : $maxTries;
|
||||
|
||||
if ($job->timeoutAt() && $job->timeoutAt() <= Carbon::now()->getTimestamp()) {
|
||||
$this->failJob($job, $e);
|
||||
}
|
||||
|
||||
if ($maxTries > 0 && $job->attempts() >= $maxTries) {
|
||||
$this->failJob($job, $e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark the given job as failed if it has exceeded the maximum allowed attempts.
|
||||
*
|
||||
* @param string $connectionName
|
||||
* @param \Illuminate\Contracts\Queue\Job $job
|
||||
* @param \Throwable $e
|
||||
* @return void
|
||||
*/
|
||||
protected function markJobAsFailedIfWillExceedMaxExceptions($connectionName, $job, Throwable $e)
|
||||
{
|
||||
if (! $this->cache || is_null($uuid = $job->uuid()) ||
|
||||
is_null($maxExceptions = $job->maxExceptions())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (! $this->cache->get('job-exceptions:'.$uuid)) {
|
||||
$this->cache->put('job-exceptions:'.$uuid, 0, Carbon::now()->addDay());
|
||||
}
|
||||
|
||||
if ($maxExceptions <= $this->cache->increment('job-exceptions:'.$uuid)) {
|
||||
$this->cache->forget('job-exceptions:'.$uuid);
|
||||
|
||||
$this->failJob($job, $e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark the given job as failed and raise the relevant event.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Queue\Job $job
|
||||
* @param \Throwable $e
|
||||
* @return void
|
||||
*/
|
||||
protected function failJob($job, Throwable $e)
|
||||
{
|
||||
return $job->fail($e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Raise the before queue job event.
|
||||
*
|
||||
* @param string $connectionName
|
||||
* @param \Illuminate\Contracts\Queue\Job $job
|
||||
* @return void
|
||||
*/
|
||||
protected function raiseBeforeJobEvent($connectionName, $job)
|
||||
{
|
||||
$this->events->dispatch(new JobProcessing(
|
||||
$connectionName, $job
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Raise the after queue job event.
|
||||
*
|
||||
* @param string $connectionName
|
||||
* @param \Illuminate\Contracts\Queue\Job $job
|
||||
* @return void
|
||||
*/
|
||||
protected function raiseAfterJobEvent($connectionName, $job)
|
||||
{
|
||||
$this->events->dispatch(new JobProcessed(
|
||||
$connectionName, $job
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Raise the exception occurred queue job event.
|
||||
*
|
||||
* @param string $connectionName
|
||||
* @param \Illuminate\Contracts\Queue\Job $job
|
||||
* @param \Throwable $e
|
||||
* @return void
|
||||
*/
|
||||
protected function raiseExceptionOccurredJobEvent($connectionName, $job, Throwable $e)
|
||||
{
|
||||
$this->events->dispatch(new JobExceptionOccurred(
|
||||
$connectionName, $job, $e
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the queue worker should restart.
|
||||
*
|
||||
* @param int|null $lastRestart
|
||||
* @return bool
|
||||
*/
|
||||
protected function queueShouldRestart($lastRestart)
|
||||
{
|
||||
return $this->getTimestampOfLastQueueRestart() != $lastRestart;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the last queue restart timestamp, or null.
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
protected function getTimestampOfLastQueueRestart()
|
||||
{
|
||||
if ($this->cache) {
|
||||
return $this->cache->get('illuminate:queue:restart');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable async signals for the process.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function listenForSignals()
|
||||
{
|
||||
pcntl_async_signals(true);
|
||||
|
||||
pcntl_signal(SIGTERM, function () {
|
||||
$this->shouldQuit = true;
|
||||
});
|
||||
|
||||
pcntl_signal(SIGUSR2, function () {
|
||||
$this->paused = true;
|
||||
});
|
||||
|
||||
pcntl_signal(SIGCONT, function () {
|
||||
$this->paused = false;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if "async" signals are supported.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function supportsAsyncSignals()
|
||||
{
|
||||
return extension_loaded('pcntl');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the memory limit has been exceeded.
|
||||
*
|
||||
* @param int $memoryLimit
|
||||
* @return bool
|
||||
*/
|
||||
public function memoryExceeded($memoryLimit)
|
||||
{
|
||||
return (memory_get_usage(true) / 1024 / 1024) >= $memoryLimit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop listening and bail out of the script.
|
||||
*
|
||||
* @param int $status
|
||||
* @return void
|
||||
*/
|
||||
public function stop($status = 0)
|
||||
{
|
||||
$this->events->dispatch(new WorkerStopping($status));
|
||||
|
||||
exit($status);
|
||||
}
|
||||
|
||||
/**
|
||||
* Kill the process.
|
||||
*
|
||||
* @param int $status
|
||||
* @return void
|
||||
*/
|
||||
public function kill($status = 0)
|
||||
{
|
||||
$this->events->dispatch(new WorkerStopping($status));
|
||||
|
||||
if (extension_loaded('posix')) {
|
||||
posix_kill(getmypid(), SIGKILL);
|
||||
}
|
||||
|
||||
exit($status);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of MaxAttemptsExceededException.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Queue\Job $job
|
||||
* @return \Illuminate\Queue\MaxAttemptsExceededException
|
||||
*/
|
||||
protected function maxAttemptsExceededException($job)
|
||||
{
|
||||
return new MaxAttemptsExceededException(
|
||||
$job->resolveName().' has been attempted too many times or run too long. The job may have previously timed out.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sleep the script for a given number of seconds.
|
||||
*
|
||||
* @param int|float $seconds
|
||||
* @return void
|
||||
*/
|
||||
public function sleep($seconds)
|
||||
{
|
||||
if ($seconds < 1) {
|
||||
usleep($seconds * 1000000);
|
||||
} else {
|
||||
sleep($seconds);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the cache repository implementation.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Cache\Repository $cache
|
||||
* @return void
|
||||
*/
|
||||
public function setCache(CacheContract $cache)
|
||||
{
|
||||
$this->cache = $cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the queue manager instance.
|
||||
*
|
||||
* @return \Illuminate\Queue\QueueManager
|
||||
*/
|
||||
public function getManager()
|
||||
{
|
||||
return $this->manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the queue manager instance.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Queue\Factory $manager
|
||||
* @return void
|
||||
*/
|
||||
public function setManager(QueueManager $manager)
|
||||
{
|
||||
$this->manager = $manager;
|
||||
}
|
||||
}
|
||||
78
vendor/laravel/framework/src/Illuminate/Queue/WorkerOptions.php
vendored
Normal file
78
vendor/laravel/framework/src/Illuminate/Queue/WorkerOptions.php
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Queue;
|
||||
|
||||
class WorkerOptions
|
||||
{
|
||||
/**
|
||||
* The number of seconds before a released job will be available.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $delay;
|
||||
|
||||
/**
|
||||
* The maximum amount of RAM the worker may consume.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $memory;
|
||||
|
||||
/**
|
||||
* The maximum number of seconds a child worker may run.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $timeout;
|
||||
|
||||
/**
|
||||
* The number of seconds to wait in between polling the queue.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $sleep;
|
||||
|
||||
/**
|
||||
* The maximum amount of times a job may be attempted.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $maxTries;
|
||||
|
||||
/**
|
||||
* Indicates if the worker should run in maintenance mode.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $force;
|
||||
|
||||
/**
|
||||
* Indicates if the worker should stop when queue is empty.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $stopWhenEmpty;
|
||||
|
||||
/**
|
||||
* Create a new worker options instance.
|
||||
*
|
||||
* @param int $delay
|
||||
* @param int $memory
|
||||
* @param int $timeout
|
||||
* @param int $sleep
|
||||
* @param int $maxTries
|
||||
* @param bool $force
|
||||
* @param bool $stopWhenEmpty
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($delay = 0, $memory = 128, $timeout = 60, $sleep = 3, $maxTries = 1, $force = false, $stopWhenEmpty = false)
|
||||
{
|
||||
$this->delay = $delay;
|
||||
$this->sleep = $sleep;
|
||||
$this->force = $force;
|
||||
$this->memory = $memory;
|
||||
$this->timeout = $timeout;
|
||||
$this->maxTries = $maxTries;
|
||||
$this->stopWhenEmpty = $stopWhenEmpty;
|
||||
}
|
||||
}
|
||||
51
vendor/laravel/framework/src/Illuminate/Queue/composer.json
vendored
Normal file
51
vendor/laravel/framework/src/Illuminate/Queue/composer.json
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
{
|
||||
"name": "illuminate/queue",
|
||||
"description": "The Illuminate Queue package.",
|
||||
"license": "MIT",
|
||||
"homepage": "https://laravel.com",
|
||||
"support": {
|
||||
"issues": "https://github.com/laravel/framework/issues",
|
||||
"source": "https://github.com/laravel/framework"
|
||||
},
|
||||
"authors": [
|
||||
{
|
||||
"name": "Taylor Otwell",
|
||||
"email": "taylor@laravel.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": "^7.2.5|^8.0",
|
||||
"ext-json": "*",
|
||||
"illuminate/console": "^7.0",
|
||||
"illuminate/container": "^7.0",
|
||||
"illuminate/contracts": "^7.0",
|
||||
"illuminate/database": "^7.0",
|
||||
"illuminate/filesystem": "^7.0",
|
||||
"illuminate/pipeline": "^7.0",
|
||||
"illuminate/support": "^7.0",
|
||||
"opis/closure": "^3.6",
|
||||
"ramsey/uuid": "^3.7|^4.0",
|
||||
"symfony/process": "^5.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Illuminate\\Queue\\": ""
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "7.x-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 and DynamoDb failed job storage (^3.155).",
|
||||
"illuminate/redis": "Required to use the Redis queue driver (^7.0).",
|
||||
"pda/pheanstalk": "Required to use the Beanstalk queue driver (^4.0)."
|
||||
},
|
||||
"config": {
|
||||
"sort-packages": true
|
||||
},
|
||||
"minimum-stability": "dev"
|
||||
}
|
||||
Reference in New Issue
Block a user