Primo Committ
This commit is contained in:
14
vendor/laravel/framework/src/Illuminate/Console/Scheduling/CacheAware.php
vendored
Normal file
14
vendor/laravel/framework/src/Illuminate/Console/Scheduling/CacheAware.php
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Console\Scheduling;
|
||||
|
||||
interface CacheAware
|
||||
{
|
||||
/**
|
||||
* Specify the cache store that should be used.
|
||||
*
|
||||
* @param string $store
|
||||
* @return $this
|
||||
*/
|
||||
public function useStore($store);
|
||||
}
|
||||
81
vendor/laravel/framework/src/Illuminate/Console/Scheduling/CacheEventMutex.php
vendored
Normal file
81
vendor/laravel/framework/src/Illuminate/Console/Scheduling/CacheEventMutex.php
vendored
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Console\Scheduling;
|
||||
|
||||
use Illuminate\Contracts\Cache\Factory as Cache;
|
||||
|
||||
class CacheEventMutex implements EventMutex, CacheAware
|
||||
{
|
||||
/**
|
||||
* The cache repository implementation.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Cache\Factory
|
||||
*/
|
||||
public $cache;
|
||||
|
||||
/**
|
||||
* The cache store that should be used.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
public $store;
|
||||
|
||||
/**
|
||||
* Create a new overlapping strategy.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Cache\Factory $cache
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Cache $cache)
|
||||
{
|
||||
$this->cache = $cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to obtain an event mutex for the given event.
|
||||
*
|
||||
* @param \Illuminate\Console\Scheduling\Event $event
|
||||
* @return bool
|
||||
*/
|
||||
public function create(Event $event)
|
||||
{
|
||||
return $this->cache->store($this->store)->add(
|
||||
$event->mutexName(), true, $event->expiresAt * 60
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if an event mutex exists for the given event.
|
||||
*
|
||||
* @param \Illuminate\Console\Scheduling\Event $event
|
||||
* @return bool
|
||||
*/
|
||||
public function exists(Event $event)
|
||||
{
|
||||
return $this->cache->store($this->store)->has($event->mutexName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the event mutex for the given event.
|
||||
*
|
||||
* @param \Illuminate\Console\Scheduling\Event $event
|
||||
* @return void
|
||||
*/
|
||||
public function forget(Event $event)
|
||||
{
|
||||
$this->cache->store($this->store)->forget($event->mutexName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify the cache store that should be used.
|
||||
*
|
||||
* @param string $store
|
||||
* @return $this
|
||||
*/
|
||||
public function useStore($store)
|
||||
{
|
||||
$this->store = $store;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
75
vendor/laravel/framework/src/Illuminate/Console/Scheduling/CacheSchedulingMutex.php
vendored
Normal file
75
vendor/laravel/framework/src/Illuminate/Console/Scheduling/CacheSchedulingMutex.php
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Console\Scheduling;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Illuminate\Contracts\Cache\Factory as Cache;
|
||||
|
||||
class CacheSchedulingMutex implements SchedulingMutex, CacheAware
|
||||
{
|
||||
/**
|
||||
* The cache factory implementation.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Cache\Factory
|
||||
*/
|
||||
public $cache;
|
||||
|
||||
/**
|
||||
* The cache store that should be used.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
public $store;
|
||||
|
||||
/**
|
||||
* Create a new scheduling strategy.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Cache\Factory $cache
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Cache $cache)
|
||||
{
|
||||
$this->cache = $cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to obtain a scheduling mutex for the given event.
|
||||
*
|
||||
* @param \Illuminate\Console\Scheduling\Event $event
|
||||
* @param \DateTimeInterface $time
|
||||
* @return bool
|
||||
*/
|
||||
public function create(Event $event, DateTimeInterface $time)
|
||||
{
|
||||
return $this->cache->store($this->store)->add(
|
||||
$event->mutexName().$time->format('Hi'), true, 3600
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a scheduling mutex exists for the given event.
|
||||
*
|
||||
* @param \Illuminate\Console\Scheduling\Event $event
|
||||
* @param \DateTimeInterface $time
|
||||
* @return bool
|
||||
*/
|
||||
public function exists(Event $event, DateTimeInterface $time)
|
||||
{
|
||||
return $this->cache->store($this->store)->has(
|
||||
$event->mutexName().$time->format('Hi')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify the cache store that should be used.
|
||||
*
|
||||
* @param string $store
|
||||
* @return $this
|
||||
*/
|
||||
public function useStore($store)
|
||||
{
|
||||
$this->store = $store;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
169
vendor/laravel/framework/src/Illuminate/Console/Scheduling/CallbackEvent.php
vendored
Normal file
169
vendor/laravel/framework/src/Illuminate/Console/Scheduling/CallbackEvent.php
vendored
Normal file
@@ -0,0 +1,169 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Console\Scheduling;
|
||||
|
||||
use Illuminate\Contracts\Container\Container;
|
||||
use Illuminate\Support\Reflector;
|
||||
use InvalidArgumentException;
|
||||
use LogicException;
|
||||
|
||||
class CallbackEvent extends Event
|
||||
{
|
||||
/**
|
||||
* The callback to call.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $callback;
|
||||
|
||||
/**
|
||||
* The parameters to pass to the method.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $parameters;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param \Illuminate\Console\Scheduling\EventMutex $mutex
|
||||
* @param string $callback
|
||||
* @param array $parameters
|
||||
* @param \DateTimeZone|string|null $timezone
|
||||
* @return void
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function __construct(EventMutex $mutex, $callback, array $parameters = [], $timezone = null)
|
||||
{
|
||||
if (! is_string($callback) && ! Reflector::isCallable($callback)) {
|
||||
throw new InvalidArgumentException(
|
||||
'Invalid scheduled callback event. Must be a string or callable.'
|
||||
);
|
||||
}
|
||||
|
||||
$this->mutex = $mutex;
|
||||
$this->callback = $callback;
|
||||
$this->parameters = $parameters;
|
||||
$this->timezone = $timezone;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the given event.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Container\Container $container
|
||||
* @return mixed
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function run(Container $container)
|
||||
{
|
||||
if ($this->description && $this->withoutOverlapping &&
|
||||
! $this->mutex->create($this)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$pid = getmypid();
|
||||
|
||||
register_shutdown_function(function () use ($pid) {
|
||||
if ($pid === getmypid()) {
|
||||
$this->removeMutex();
|
||||
}
|
||||
});
|
||||
|
||||
parent::callBeforeCallbacks($container);
|
||||
|
||||
try {
|
||||
$response = is_object($this->callback)
|
||||
? $container->call([$this->callback, '__invoke'], $this->parameters)
|
||||
: $container->call($this->callback, $this->parameters);
|
||||
} finally {
|
||||
$this->removeMutex();
|
||||
|
||||
parent::callAfterCallbacks($container);
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the mutex for the event.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function removeMutex()
|
||||
{
|
||||
if ($this->description && $this->withoutOverlapping) {
|
||||
$this->mutex->forget($this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Do not allow the event to overlap each other.
|
||||
*
|
||||
* @param int $expiresAt
|
||||
* @return $this
|
||||
*
|
||||
* @throws \LogicException
|
||||
*/
|
||||
public function withoutOverlapping($expiresAt = 1440)
|
||||
{
|
||||
if (! isset($this->description)) {
|
||||
throw new LogicException(
|
||||
"A scheduled event name is required to prevent overlapping. Use the 'name' method before 'withoutOverlapping'."
|
||||
);
|
||||
}
|
||||
|
||||
$this->withoutOverlapping = true;
|
||||
|
||||
$this->expiresAt = $expiresAt;
|
||||
|
||||
return $this->skip(function () {
|
||||
return $this->mutex->exists($this);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow the event to only run on one server for each cron expression.
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @throws \LogicException
|
||||
*/
|
||||
public function onOneServer()
|
||||
{
|
||||
if (! isset($this->description)) {
|
||||
throw new LogicException(
|
||||
"A scheduled event name is required to only run on one server. Use the 'name' method before 'onOneServer'."
|
||||
);
|
||||
}
|
||||
|
||||
$this->onOneServer = true;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mutex name for the scheduled command.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function mutexName()
|
||||
{
|
||||
return 'framework/schedule-'.sha1($this->description);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the summary of the event for display.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSummaryForDisplay()
|
||||
{
|
||||
if (is_string($this->description)) {
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
return is_string($this->callback) ? $this->callback : 'Callback';
|
||||
}
|
||||
}
|
||||
75
vendor/laravel/framework/src/Illuminate/Console/Scheduling/CommandBuilder.php
vendored
Normal file
75
vendor/laravel/framework/src/Illuminate/Console/Scheduling/CommandBuilder.php
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Console\Scheduling;
|
||||
|
||||
use Illuminate\Console\Application;
|
||||
use Illuminate\Support\ProcessUtils;
|
||||
|
||||
class CommandBuilder
|
||||
{
|
||||
/**
|
||||
* Build the command for the given event.
|
||||
*
|
||||
* @param \Illuminate\Console\Scheduling\Event $event
|
||||
* @return string
|
||||
*/
|
||||
public function buildCommand(Event $event)
|
||||
{
|
||||
if ($event->runInBackground) {
|
||||
return $this->buildBackgroundCommand($event);
|
||||
}
|
||||
|
||||
return $this->buildForegroundCommand($event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the command for running the event in the foreground.
|
||||
*
|
||||
* @param \Illuminate\Console\Scheduling\Event $event
|
||||
* @return string
|
||||
*/
|
||||
protected function buildForegroundCommand(Event $event)
|
||||
{
|
||||
$output = ProcessUtils::escapeArgument($event->output);
|
||||
|
||||
return $this->ensureCorrectUser(
|
||||
$event, $event->command.($event->shouldAppendOutput ? ' >> ' : ' > ').$output.' 2>&1'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the command for running the event in the background.
|
||||
*
|
||||
* @param \Illuminate\Console\Scheduling\Event $event
|
||||
* @return string
|
||||
*/
|
||||
protected function buildBackgroundCommand(Event $event)
|
||||
{
|
||||
$output = ProcessUtils::escapeArgument($event->output);
|
||||
|
||||
$redirect = $event->shouldAppendOutput ? ' >> ' : ' > ';
|
||||
|
||||
$finished = Application::formatCommandString('schedule:finish').' "'.$event->mutexName().'"';
|
||||
|
||||
if (windows_os()) {
|
||||
return 'start /b cmd /c "('.$event->command.' & '.$finished.' "%errorlevel%")'.$redirect.$output.' 2>&1"';
|
||||
}
|
||||
|
||||
return $this->ensureCorrectUser($event,
|
||||
'('.$event->command.$redirect.$output.' 2>&1 ; '.$finished.' "$?") > '
|
||||
.ProcessUtils::escapeArgument($event->getDefaultOutput()).' 2>&1 &'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finalize the event's command syntax with the correct user.
|
||||
*
|
||||
* @param \Illuminate\Console\Scheduling\Event $event
|
||||
* @param string $command
|
||||
* @return string
|
||||
*/
|
||||
protected function ensureCorrectUser(Event $event, $command)
|
||||
{
|
||||
return $event->user && ! windows_os() ? 'sudo -u '.$event->user.' -- sh -c \''.$command.'\'' : $command;
|
||||
}
|
||||
}
|
||||
901
vendor/laravel/framework/src/Illuminate/Console/Scheduling/Event.php
vendored
Normal file
901
vendor/laravel/framework/src/Illuminate/Console/Scheduling/Event.php
vendored
Normal file
@@ -0,0 +1,901 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Console\Scheduling;
|
||||
|
||||
use Closure;
|
||||
use Cron\CronExpression;
|
||||
use GuzzleHttp\Client as HttpClient;
|
||||
use GuzzleHttp\Exception\TransferException;
|
||||
use Illuminate\Contracts\Container\Container;
|
||||
use Illuminate\Contracts\Debug\ExceptionHandler;
|
||||
use Illuminate\Contracts\Mail\Mailer;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\Date;
|
||||
use Illuminate\Support\Reflector;
|
||||
use Illuminate\Support\Traits\Macroable;
|
||||
use Illuminate\Support\Traits\ReflectsClosures;
|
||||
use Psr\Http\Client\ClientExceptionInterface;
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
class Event
|
||||
{
|
||||
use Macroable, ManagesFrequencies, ReflectsClosures;
|
||||
|
||||
/**
|
||||
* The command string.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $command;
|
||||
|
||||
/**
|
||||
* The cron expression representing the event's frequency.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $expression = '* * * * *';
|
||||
|
||||
/**
|
||||
* The timezone the date should be evaluated on.
|
||||
*
|
||||
* @var \DateTimeZone|string
|
||||
*/
|
||||
public $timezone;
|
||||
|
||||
/**
|
||||
* The user the command should run as.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $user;
|
||||
|
||||
/**
|
||||
* The list of environments the command should run under.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $environments = [];
|
||||
|
||||
/**
|
||||
* Indicates if the command should run in maintenance mode.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $evenInMaintenanceMode = false;
|
||||
|
||||
/**
|
||||
* Indicates if the command should not overlap itself.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $withoutOverlapping = false;
|
||||
|
||||
/**
|
||||
* Indicates if the command should only be allowed to run on one server for each cron expression.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $onOneServer = false;
|
||||
|
||||
/**
|
||||
* The amount of time the mutex should be valid.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $expiresAt = 1440;
|
||||
|
||||
/**
|
||||
* Indicates if the command should run in background.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $runInBackground = false;
|
||||
|
||||
/**
|
||||
* The array of filter callbacks.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $filters = [];
|
||||
|
||||
/**
|
||||
* The array of reject callbacks.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $rejects = [];
|
||||
|
||||
/**
|
||||
* The location that output should be sent to.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $output = '/dev/null';
|
||||
|
||||
/**
|
||||
* Indicates whether output should be appended.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $shouldAppendOutput = false;
|
||||
|
||||
/**
|
||||
* The array of callbacks to be run before the event is started.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $beforeCallbacks = [];
|
||||
|
||||
/**
|
||||
* The array of callbacks to be run after the event is finished.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $afterCallbacks = [];
|
||||
|
||||
/**
|
||||
* The human readable description of the event.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $description;
|
||||
|
||||
/**
|
||||
* The event mutex implementation.
|
||||
*
|
||||
* @var \Illuminate\Console\Scheduling\EventMutex
|
||||
*/
|
||||
public $mutex;
|
||||
|
||||
/**
|
||||
* The exit status code of the command.
|
||||
*
|
||||
* @var int|null
|
||||
*/
|
||||
public $exitCode;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param \Illuminate\Console\Scheduling\EventMutex $mutex
|
||||
* @param string $command
|
||||
* @param \DateTimeZone|string|null $timezone
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(EventMutex $mutex, $command, $timezone = null)
|
||||
{
|
||||
$this->mutex = $mutex;
|
||||
$this->command = $command;
|
||||
$this->timezone = $timezone;
|
||||
|
||||
$this->output = $this->getDefaultOutput();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default output depending on the OS.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDefaultOutput()
|
||||
{
|
||||
return (DIRECTORY_SEPARATOR === '\\') ? 'NUL' : '/dev/null';
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the given event.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Container\Container $container
|
||||
* @return void
|
||||
*/
|
||||
public function run(Container $container)
|
||||
{
|
||||
if ($this->withoutOverlapping &&
|
||||
! $this->mutex->create($this)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->runInBackground
|
||||
? $this->runCommandInBackground($container)
|
||||
: $this->runCommandInForeground($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mutex name for the scheduled command.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function mutexName()
|
||||
{
|
||||
return 'framework'.DIRECTORY_SEPARATOR.'schedule-'.sha1($this->expression.$this->command);
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the command in the foreground.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Container\Container $container
|
||||
* @return void
|
||||
*/
|
||||
protected function runCommandInForeground(Container $container)
|
||||
{
|
||||
$this->callBeforeCallbacks($container);
|
||||
|
||||
$this->exitCode = Process::fromShellCommandline($this->buildCommand(), base_path(), null, null, null)->run();
|
||||
|
||||
$this->callAfterCallbacks($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the command in the background.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Container\Container $container
|
||||
* @return void
|
||||
*/
|
||||
protected function runCommandInBackground(Container $container)
|
||||
{
|
||||
$this->callBeforeCallbacks($container);
|
||||
|
||||
Process::fromShellCommandline($this->buildCommand(), base_path(), null, null, null)->run();
|
||||
}
|
||||
|
||||
/**
|
||||
* Call all of the "before" callbacks for the event.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Container\Container $container
|
||||
* @return void
|
||||
*/
|
||||
public function callBeforeCallbacks(Container $container)
|
||||
{
|
||||
foreach ($this->beforeCallbacks as $callback) {
|
||||
$container->call($callback);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Call all of the "after" callbacks for the event.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Container\Container $container
|
||||
* @return void
|
||||
*/
|
||||
public function callAfterCallbacks(Container $container)
|
||||
{
|
||||
foreach ($this->afterCallbacks as $callback) {
|
||||
$container->call($callback);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Call all of the "after" callbacks for the event.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Container\Container $container
|
||||
* @param int $exitCode
|
||||
* @return void
|
||||
*/
|
||||
public function callAfterCallbacksWithExitCode(Container $container, $exitCode)
|
||||
{
|
||||
$this->exitCode = (int) $exitCode;
|
||||
|
||||
$this->callAfterCallbacks($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the command string.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function buildCommand()
|
||||
{
|
||||
return (new CommandBuilder)->buildCommand($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the given event should run based on the Cron expression.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Foundation\Application $app
|
||||
* @return bool
|
||||
*/
|
||||
public function isDue($app)
|
||||
{
|
||||
if (! $this->runsInMaintenanceMode() && $app->isDownForMaintenance()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->expressionPasses() &&
|
||||
$this->runsInEnvironment($app->environment());
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the event runs in maintenance mode.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function runsInMaintenanceMode()
|
||||
{
|
||||
return $this->evenInMaintenanceMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the Cron expression passes.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function expressionPasses()
|
||||
{
|
||||
$date = Carbon::now();
|
||||
|
||||
if ($this->timezone) {
|
||||
$date->setTimezone($this->timezone);
|
||||
}
|
||||
|
||||
return CronExpression::factory($this->expression)->isDue($date->toDateTimeString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the event runs in the given environment.
|
||||
*
|
||||
* @param string $environment
|
||||
* @return bool
|
||||
*/
|
||||
public function runsInEnvironment($environment)
|
||||
{
|
||||
return empty($this->environments) || in_array($environment, $this->environments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the filters pass for the event.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Foundation\Application $app
|
||||
* @return bool
|
||||
*/
|
||||
public function filtersPass($app)
|
||||
{
|
||||
foreach ($this->filters as $callback) {
|
||||
if (! $app->call($callback)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->rejects as $callback) {
|
||||
if ($app->call($callback)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure that the output is stored on disk in a log file.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function storeOutput()
|
||||
{
|
||||
$this->ensureOutputIsBeingCaptured();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the output of the command to a given location.
|
||||
*
|
||||
* @param string $location
|
||||
* @param bool $append
|
||||
* @return $this
|
||||
*/
|
||||
public function sendOutputTo($location, $append = false)
|
||||
{
|
||||
$this->output = $location;
|
||||
|
||||
$this->shouldAppendOutput = $append;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append the output of the command to a given location.
|
||||
*
|
||||
* @param string $location
|
||||
* @return $this
|
||||
*/
|
||||
public function appendOutputTo($location)
|
||||
{
|
||||
return $this->sendOutputTo($location, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* E-mail the results of the scheduled operation.
|
||||
*
|
||||
* @param array|mixed $addresses
|
||||
* @param bool $onlyIfOutputExists
|
||||
* @return $this
|
||||
*
|
||||
* @throws \LogicException
|
||||
*/
|
||||
public function emailOutputTo($addresses, $onlyIfOutputExists = false)
|
||||
{
|
||||
$this->ensureOutputIsBeingCaptured();
|
||||
|
||||
$addresses = Arr::wrap($addresses);
|
||||
|
||||
return $this->then(function (Mailer $mailer) use ($addresses, $onlyIfOutputExists) {
|
||||
$this->emailOutput($mailer, $addresses, $onlyIfOutputExists);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* E-mail the results of the scheduled operation if it produces output.
|
||||
*
|
||||
* @param array|mixed $addresses
|
||||
* @return $this
|
||||
*
|
||||
* @throws \LogicException
|
||||
*/
|
||||
public function emailWrittenOutputTo($addresses)
|
||||
{
|
||||
return $this->emailOutputTo($addresses, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* E-mail the results of the scheduled operation if it fails.
|
||||
*
|
||||
* @param array|mixed $addresses
|
||||
* @return $this
|
||||
*/
|
||||
public function emailOutputOnFailure($addresses)
|
||||
{
|
||||
$this->ensureOutputIsBeingCaptured();
|
||||
|
||||
$addresses = Arr::wrap($addresses);
|
||||
|
||||
return $this->onFailure(function (Mailer $mailer) use ($addresses) {
|
||||
$this->emailOutput($mailer, $addresses, false);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure that the command output is being captured.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function ensureOutputIsBeingCaptured()
|
||||
{
|
||||
if (is_null($this->output) || $this->output == $this->getDefaultOutput()) {
|
||||
$this->sendOutputTo(storage_path('logs/schedule-'.sha1($this->mutexName()).'.log'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* E-mail the output of the event to the recipients.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Mail\Mailer $mailer
|
||||
* @param array $addresses
|
||||
* @param bool $onlyIfOutputExists
|
||||
* @return void
|
||||
*/
|
||||
protected function emailOutput(Mailer $mailer, $addresses, $onlyIfOutputExists = false)
|
||||
{
|
||||
$text = file_exists($this->output) ? file_get_contents($this->output) : '';
|
||||
|
||||
if ($onlyIfOutputExists && empty($text)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$mailer->raw($text, function ($m) use ($addresses) {
|
||||
$m->to($addresses)->subject($this->getEmailSubject());
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the e-mail subject line for output results.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getEmailSubject()
|
||||
{
|
||||
if ($this->description) {
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
return "Scheduled Job Output For [{$this->command}]";
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a callback to ping a given URL before the job runs.
|
||||
*
|
||||
* @param string $url
|
||||
* @return $this
|
||||
*/
|
||||
public function pingBefore($url)
|
||||
{
|
||||
return $this->before($this->pingCallback($url));
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a callback to ping a given URL before the job runs if the given condition is true.
|
||||
*
|
||||
* @param bool $value
|
||||
* @param string $url
|
||||
* @return $this
|
||||
*/
|
||||
public function pingBeforeIf($value, $url)
|
||||
{
|
||||
return $value ? $this->pingBefore($url) : $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a callback to ping a given URL after the job runs.
|
||||
*
|
||||
* @param string $url
|
||||
* @return $this
|
||||
*/
|
||||
public function thenPing($url)
|
||||
{
|
||||
return $this->then($this->pingCallback($url));
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a callback to ping a given URL after the job runs if the given condition is true.
|
||||
*
|
||||
* @param bool $value
|
||||
* @param string $url
|
||||
* @return $this
|
||||
*/
|
||||
public function thenPingIf($value, $url)
|
||||
{
|
||||
return $value ? $this->thenPing($url) : $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a callback to ping a given URL if the operation succeeds.
|
||||
*
|
||||
* @param string $url
|
||||
* @return $this
|
||||
*/
|
||||
public function pingOnSuccess($url)
|
||||
{
|
||||
return $this->onSuccess($this->pingCallback($url));
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a callback to ping a given URL if the operation fails.
|
||||
*
|
||||
* @param string $url
|
||||
* @return $this
|
||||
*/
|
||||
public function pingOnFailure($url)
|
||||
{
|
||||
return $this->onFailure($this->pingCallback($url));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the callback that pings the given URL.
|
||||
*
|
||||
* @param string $url
|
||||
* @return \Closure
|
||||
*/
|
||||
protected function pingCallback($url)
|
||||
{
|
||||
return function (Container $container, HttpClient $http) use ($url) {
|
||||
try {
|
||||
$http->request('GET', $url);
|
||||
} catch (ClientExceptionInterface|TransferException $e) {
|
||||
$container->make(ExceptionHandler::class)->report($e);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* State that the command should run in background.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function runInBackground()
|
||||
{
|
||||
$this->runInBackground = true;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set which user the command should run as.
|
||||
*
|
||||
* @param string $user
|
||||
* @return $this
|
||||
*/
|
||||
public function user($user)
|
||||
{
|
||||
$this->user = $user;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Limit the environments the command should run in.
|
||||
*
|
||||
* @param array|mixed $environments
|
||||
* @return $this
|
||||
*/
|
||||
public function environments($environments)
|
||||
{
|
||||
$this->environments = is_array($environments) ? $environments : func_get_args();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* State that the command should run even in maintenance mode.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function evenInMaintenanceMode()
|
||||
{
|
||||
$this->evenInMaintenanceMode = true;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Do not allow the event to overlap each other.
|
||||
*
|
||||
* @param int $expiresAt
|
||||
* @return $this
|
||||
*/
|
||||
public function withoutOverlapping($expiresAt = 1440)
|
||||
{
|
||||
$this->withoutOverlapping = true;
|
||||
|
||||
$this->expiresAt = $expiresAt;
|
||||
|
||||
return $this->then(function () {
|
||||
$this->mutex->forget($this);
|
||||
})->skip(function () {
|
||||
return $this->mutex->exists($this);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow the event to only run on one server for each cron expression.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function onOneServer()
|
||||
{
|
||||
$this->onOneServer = true;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a callback to further filter the schedule.
|
||||
*
|
||||
* @param \Closure|bool $callback
|
||||
* @return $this
|
||||
*/
|
||||
public function when($callback)
|
||||
{
|
||||
$this->filters[] = Reflector::isCallable($callback) ? $callback : function () use ($callback) {
|
||||
return $callback;
|
||||
};
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a callback to further filter the schedule.
|
||||
*
|
||||
* @param \Closure|bool $callback
|
||||
* @return $this
|
||||
*/
|
||||
public function skip($callback)
|
||||
{
|
||||
$this->rejects[] = Reflector::isCallable($callback) ? $callback : function () use ($callback) {
|
||||
return $callback;
|
||||
};
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a callback to be called before the operation.
|
||||
*
|
||||
* @param \Closure $callback
|
||||
* @return $this
|
||||
*/
|
||||
public function before(Closure $callback)
|
||||
{
|
||||
$this->beforeCallbacks[] = $callback;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a callback to be called after the operation.
|
||||
*
|
||||
* @param \Closure $callback
|
||||
* @return $this
|
||||
*/
|
||||
public function after(Closure $callback)
|
||||
{
|
||||
return $this->then($callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a callback to be called after the operation.
|
||||
*
|
||||
* @param \Closure $callback
|
||||
* @return $this
|
||||
*/
|
||||
public function then(Closure $callback)
|
||||
{
|
||||
$this->afterCallbacks[] = $callback;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a callback that uses the output after the job runs.
|
||||
*
|
||||
* @param \Closure $callback
|
||||
* @param bool $onlyIfOutputExists
|
||||
* @return $this
|
||||
*/
|
||||
public function thenWithOutput(Closure $callback, $onlyIfOutputExists = false)
|
||||
{
|
||||
$this->ensureOutputIsBeingCaptured();
|
||||
|
||||
return $this->then($this->withOutputCallback($callback, $onlyIfOutputExists));
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a callback to be called if the operation succeeds.
|
||||
*
|
||||
* @param \Closure $callback
|
||||
* @return $this
|
||||
*/
|
||||
public function onSuccess(Closure $callback)
|
||||
{
|
||||
return $this->then(function (Container $container) use ($callback) {
|
||||
if (0 === $this->exitCode) {
|
||||
$container->call($callback);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a callback that uses the output if the operation succeeds.
|
||||
*
|
||||
* @param \Closure $callback
|
||||
* @param bool $onlyIfOutputExists
|
||||
* @return $this
|
||||
*/
|
||||
public function onSuccessWithOutput(Closure $callback, $onlyIfOutputExists = false)
|
||||
{
|
||||
$this->ensureOutputIsBeingCaptured();
|
||||
|
||||
return $this->onSuccess($this->withOutputCallback($callback, $onlyIfOutputExists));
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a callback to be called if the operation fails.
|
||||
*
|
||||
* @param \Closure $callback
|
||||
* @return $this
|
||||
*/
|
||||
public function onFailure(Closure $callback)
|
||||
{
|
||||
return $this->then(function (Container $container) use ($callback) {
|
||||
if (0 !== $this->exitCode) {
|
||||
$container->call($callback);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a callback that uses the output if the operation fails.
|
||||
*
|
||||
* @param \Closure $callback
|
||||
* @param bool $onlyIfOutputExists
|
||||
* @return $this
|
||||
*/
|
||||
public function onFailureWithOutput(Closure $callback, $onlyIfOutputExists = false)
|
||||
{
|
||||
$this->ensureOutputIsBeingCaptured();
|
||||
|
||||
return $this->onFailure($this->withOutputCallback($callback, $onlyIfOutputExists));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a callback that provides output.
|
||||
*
|
||||
* @param \Closure $callback
|
||||
* @param bool $onlyIfOutputExists
|
||||
* @return \Closure
|
||||
*/
|
||||
protected function withOutputCallback(Closure $callback, $onlyIfOutputExists = false)
|
||||
{
|
||||
return function (Container $container) use ($callback, $onlyIfOutputExists) {
|
||||
$output = $this->output && file_exists($this->output) ? file_get_contents($this->output) : '';
|
||||
|
||||
return $onlyIfOutputExists && empty($output)
|
||||
? null
|
||||
: $container->call($callback, ['output' => $output]);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the human-friendly description of the event.
|
||||
*
|
||||
* @param string $description
|
||||
* @return $this
|
||||
*/
|
||||
public function name($description)
|
||||
{
|
||||
return $this->description($description);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the human-friendly description of the event.
|
||||
*
|
||||
* @param string $description
|
||||
* @return $this
|
||||
*/
|
||||
public function description($description)
|
||||
{
|
||||
$this->description = $description;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the summary of the event for display.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSummaryForDisplay()
|
||||
{
|
||||
if (is_string($this->description)) {
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
return $this->buildCommand();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the next due date for an event.
|
||||
*
|
||||
* @param \DateTimeInterface|string $currentTime
|
||||
* @param int $nth
|
||||
* @param bool $allowCurrentDate
|
||||
* @return \Illuminate\Support\Carbon
|
||||
*/
|
||||
public function nextRunDate($currentTime = 'now', $nth = 0, $allowCurrentDate = false)
|
||||
{
|
||||
return Date::instance(CronExpression::factory(
|
||||
$this->getExpression()
|
||||
)->getNextRunDate($currentTime, $nth, $allowCurrentDate, $this->timezone));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Cron expression for the event.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getExpression()
|
||||
{
|
||||
return $this->expression;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the event mutex implementation to be used.
|
||||
*
|
||||
* @param \Illuminate\Console\Scheduling\EventMutex $mutex
|
||||
* @return $this
|
||||
*/
|
||||
public function preventOverlapsUsing(EventMutex $mutex)
|
||||
{
|
||||
$this->mutex = $mutex;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
30
vendor/laravel/framework/src/Illuminate/Console/Scheduling/EventMutex.php
vendored
Normal file
30
vendor/laravel/framework/src/Illuminate/Console/Scheduling/EventMutex.php
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Console\Scheduling;
|
||||
|
||||
interface EventMutex
|
||||
{
|
||||
/**
|
||||
* Attempt to obtain an event mutex for the given event.
|
||||
*
|
||||
* @param \Illuminate\Console\Scheduling\Event $event
|
||||
* @return bool
|
||||
*/
|
||||
public function create(Event $event);
|
||||
|
||||
/**
|
||||
* Determine if an event mutex exists for the given event.
|
||||
*
|
||||
* @param \Illuminate\Console\Scheduling\Event $event
|
||||
* @return bool
|
||||
*/
|
||||
public function exists(Event $event);
|
||||
|
||||
/**
|
||||
* Clear the event mutex for the given event.
|
||||
*
|
||||
* @param \Illuminate\Console\Scheduling\Event $event
|
||||
* @return void
|
||||
*/
|
||||
public function forget(Event $event);
|
||||
}
|
||||
513
vendor/laravel/framework/src/Illuminate/Console/Scheduling/ManagesFrequencies.php
vendored
Normal file
513
vendor/laravel/framework/src/Illuminate/Console/Scheduling/ManagesFrequencies.php
vendored
Normal file
@@ -0,0 +1,513 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Console\Scheduling;
|
||||
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
trait ManagesFrequencies
|
||||
{
|
||||
/**
|
||||
* The Cron expression representing the event's frequency.
|
||||
*
|
||||
* @param string $expression
|
||||
* @return $this
|
||||
*/
|
||||
public function cron($expression)
|
||||
{
|
||||
$this->expression = $expression;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule the event to run between start and end time.
|
||||
*
|
||||
* @param string $startTime
|
||||
* @param string $endTime
|
||||
* @return $this
|
||||
*/
|
||||
public function between($startTime, $endTime)
|
||||
{
|
||||
return $this->when($this->inTimeInterval($startTime, $endTime));
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule the event to not run between start and end time.
|
||||
*
|
||||
* @param string $startTime
|
||||
* @param string $endTime
|
||||
* @return $this
|
||||
*/
|
||||
public function unlessBetween($startTime, $endTime)
|
||||
{
|
||||
return $this->skip($this->inTimeInterval($startTime, $endTime));
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule the event to run between start and end time.
|
||||
*
|
||||
* @param string $startTime
|
||||
* @param string $endTime
|
||||
* @return \Closure
|
||||
*/
|
||||
private function inTimeInterval($startTime, $endTime)
|
||||
{
|
||||
[$now, $startTime, $endTime] = [
|
||||
Carbon::now($this->timezone),
|
||||
Carbon::parse($startTime, $this->timezone),
|
||||
Carbon::parse($endTime, $this->timezone),
|
||||
];
|
||||
|
||||
if ($endTime->lessThan($startTime)) {
|
||||
if ($startTime->greaterThan($now)) {
|
||||
$startTime->subDay(1);
|
||||
} else {
|
||||
$endTime->addDay(1);
|
||||
}
|
||||
}
|
||||
|
||||
return function () use ($now, $startTime, $endTime) {
|
||||
return $now->between($startTime, $endTime);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule the event to run every minute.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function everyMinute()
|
||||
{
|
||||
return $this->spliceIntoPosition(1, '*');
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule the event to run every two minutes.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function everyTwoMinutes()
|
||||
{
|
||||
return $this->spliceIntoPosition(1, '*/2');
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule the event to run every three minutes.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function everyThreeMinutes()
|
||||
{
|
||||
return $this->spliceIntoPosition(1, '*/3');
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule the event to run every four minutes.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function everyFourMinutes()
|
||||
{
|
||||
return $this->spliceIntoPosition(1, '*/4');
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule the event to run every five minutes.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function everyFiveMinutes()
|
||||
{
|
||||
return $this->spliceIntoPosition(1, '*/5');
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule the event to run every ten minutes.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function everyTenMinutes()
|
||||
{
|
||||
return $this->spliceIntoPosition(1, '*/10');
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule the event to run every fifteen minutes.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function everyFifteenMinutes()
|
||||
{
|
||||
return $this->spliceIntoPosition(1, '*/15');
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule the event to run every thirty minutes.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function everyThirtyMinutes()
|
||||
{
|
||||
return $this->spliceIntoPosition(1, '0,30');
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule the event to run hourly.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function hourly()
|
||||
{
|
||||
return $this->spliceIntoPosition(1, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule the event to run hourly at a given offset in the hour.
|
||||
*
|
||||
* @param array|int $offset
|
||||
* @return $this
|
||||
*/
|
||||
public function hourlyAt($offset)
|
||||
{
|
||||
$offset = is_array($offset) ? implode(',', $offset) : $offset;
|
||||
|
||||
return $this->spliceIntoPosition(1, $offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule the event to run every two hours.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function everyTwoHours()
|
||||
{
|
||||
return $this->spliceIntoPosition(1, 0)
|
||||
->spliceIntoPosition(2, '*/2');
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule the event to run every three hours.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function everyThreeHours()
|
||||
{
|
||||
return $this->spliceIntoPosition(1, 0)
|
||||
->spliceIntoPosition(2, '*/3');
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule the event to run every four hours.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function everyFourHours()
|
||||
{
|
||||
return $this->spliceIntoPosition(1, 0)
|
||||
->spliceIntoPosition(2, '*/4');
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule the event to run every six hours.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function everySixHours()
|
||||
{
|
||||
return $this->spliceIntoPosition(1, 0)
|
||||
->spliceIntoPosition(2, '*/6');
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule the event to run daily.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function daily()
|
||||
{
|
||||
return $this->spliceIntoPosition(1, 0)
|
||||
->spliceIntoPosition(2, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule the command at a given time.
|
||||
*
|
||||
* @param string $time
|
||||
* @return $this
|
||||
*/
|
||||
public function at($time)
|
||||
{
|
||||
return $this->dailyAt($time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule the event to run daily at a given time (10:00, 19:30, etc).
|
||||
*
|
||||
* @param string $time
|
||||
* @return $this
|
||||
*/
|
||||
public function dailyAt($time)
|
||||
{
|
||||
$segments = explode(':', $time);
|
||||
|
||||
return $this->spliceIntoPosition(2, (int) $segments[0])
|
||||
->spliceIntoPosition(1, count($segments) === 2 ? (int) $segments[1] : '0');
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule the event to run twice daily.
|
||||
*
|
||||
* @param int $first
|
||||
* @param int $second
|
||||
* @return $this
|
||||
*/
|
||||
public function twiceDaily($first = 1, $second = 13)
|
||||
{
|
||||
$hours = $first.','.$second;
|
||||
|
||||
return $this->spliceIntoPosition(1, 0)
|
||||
->spliceIntoPosition(2, $hours);
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule the event to run only on weekdays.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function weekdays()
|
||||
{
|
||||
return $this->spliceIntoPosition(5, '1-5');
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule the event to run only on weekends.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function weekends()
|
||||
{
|
||||
return $this->spliceIntoPosition(5, '0,6');
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule the event to run only on Mondays.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function mondays()
|
||||
{
|
||||
return $this->days(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule the event to run only on Tuesdays.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function tuesdays()
|
||||
{
|
||||
return $this->days(2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule the event to run only on Wednesdays.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function wednesdays()
|
||||
{
|
||||
return $this->days(3);
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule the event to run only on Thursdays.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function thursdays()
|
||||
{
|
||||
return $this->days(4);
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule the event to run only on Fridays.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function fridays()
|
||||
{
|
||||
return $this->days(5);
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule the event to run only on Saturdays.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function saturdays()
|
||||
{
|
||||
return $this->days(6);
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule the event to run only on Sundays.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function sundays()
|
||||
{
|
||||
return $this->days(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule the event to run weekly.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function weekly()
|
||||
{
|
||||
return $this->spliceIntoPosition(1, 0)
|
||||
->spliceIntoPosition(2, 0)
|
||||
->spliceIntoPosition(5, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule the event to run weekly on a given day and time.
|
||||
*
|
||||
* @param int $day
|
||||
* @param string $time
|
||||
* @return $this
|
||||
*/
|
||||
public function weeklyOn($day, $time = '0:0')
|
||||
{
|
||||
$this->dailyAt($time);
|
||||
|
||||
return $this->spliceIntoPosition(5, $day);
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule the event to run monthly.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function monthly()
|
||||
{
|
||||
return $this->spliceIntoPosition(1, 0)
|
||||
->spliceIntoPosition(2, 0)
|
||||
->spliceIntoPosition(3, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule the event to run monthly on a given day and time.
|
||||
*
|
||||
* @param int $day
|
||||
* @param string $time
|
||||
* @return $this
|
||||
*/
|
||||
public function monthlyOn($day = 1, $time = '0:0')
|
||||
{
|
||||
$this->dailyAt($time);
|
||||
|
||||
return $this->spliceIntoPosition(3, $day);
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule the event to run twice monthly at a given time.
|
||||
*
|
||||
* @param int $first
|
||||
* @param int $second
|
||||
* @param string $time
|
||||
* @return $this
|
||||
*/
|
||||
public function twiceMonthly($first = 1, $second = 16, $time = '0:0')
|
||||
{
|
||||
$days = $first.','.$second;
|
||||
|
||||
$this->dailyAt($time);
|
||||
|
||||
return $this->spliceIntoPosition(1, 0)
|
||||
->spliceIntoPosition(2, 0)
|
||||
->spliceIntoPosition(3, $days);
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule the event to run on the last day of the month.
|
||||
*
|
||||
* @param string $time
|
||||
* @return $this
|
||||
*/
|
||||
public function lastDayOfMonth($time = '0:0')
|
||||
{
|
||||
$this->dailyAt($time);
|
||||
|
||||
return $this->spliceIntoPosition(3, Carbon::now()->endOfMonth()->day);
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule the event to run quarterly.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function quarterly()
|
||||
{
|
||||
return $this->spliceIntoPosition(1, 0)
|
||||
->spliceIntoPosition(2, 0)
|
||||
->spliceIntoPosition(3, 1)
|
||||
->spliceIntoPosition(4, '1-12/3');
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule the event to run yearly.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function yearly()
|
||||
{
|
||||
return $this->spliceIntoPosition(1, 0)
|
||||
->spliceIntoPosition(2, 0)
|
||||
->spliceIntoPosition(3, 1)
|
||||
->spliceIntoPosition(4, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the days of the week the command should run on.
|
||||
*
|
||||
* @param array|mixed $days
|
||||
* @return $this
|
||||
*/
|
||||
public function days($days)
|
||||
{
|
||||
$days = is_array($days) ? $days : func_get_args();
|
||||
|
||||
return $this->spliceIntoPosition(5, implode(',', $days));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the timezone the date should be evaluated on.
|
||||
*
|
||||
* @param \DateTimeZone|string $timezone
|
||||
* @return $this
|
||||
*/
|
||||
public function timezone($timezone)
|
||||
{
|
||||
$this->timezone = $timezone;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Splice the given value into the given position of the expression.
|
||||
*
|
||||
* @param int $position
|
||||
* @param string $value
|
||||
* @return $this
|
||||
*/
|
||||
protected function spliceIntoPosition($position, $value)
|
||||
{
|
||||
$segments = explode(' ', $this->expression);
|
||||
|
||||
$segments[$position - 1] = $value;
|
||||
|
||||
return $this->cron(implode(' ', $segments));
|
||||
}
|
||||
}
|
||||
312
vendor/laravel/framework/src/Illuminate/Console/Scheduling/Schedule.php
vendored
Normal file
312
vendor/laravel/framework/src/Illuminate/Console/Scheduling/Schedule.php
vendored
Normal file
@@ -0,0 +1,312 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Console\Scheduling;
|
||||
|
||||
use Closure;
|
||||
use DateTimeInterface;
|
||||
use Illuminate\Console\Application;
|
||||
use Illuminate\Container\Container;
|
||||
use Illuminate\Contracts\Bus\Dispatcher;
|
||||
use Illuminate\Contracts\Container\BindingResolutionException;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Queue\CallQueuedClosure;
|
||||
use Illuminate\Support\ProcessUtils;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Traits\Macroable;
|
||||
use RuntimeException;
|
||||
|
||||
class Schedule
|
||||
{
|
||||
use Macroable;
|
||||
|
||||
/**
|
||||
* All of the events on the schedule.
|
||||
*
|
||||
* @var \Illuminate\Console\Scheduling\Event[]
|
||||
*/
|
||||
protected $events = [];
|
||||
|
||||
/**
|
||||
* The event mutex implementation.
|
||||
*
|
||||
* @var \Illuminate\Console\Scheduling\EventMutex
|
||||
*/
|
||||
protected $eventMutex;
|
||||
|
||||
/**
|
||||
* The scheduling mutex implementation.
|
||||
*
|
||||
* @var \Illuminate\Console\Scheduling\SchedulingMutex
|
||||
*/
|
||||
protected $schedulingMutex;
|
||||
|
||||
/**
|
||||
* The timezone the date should be evaluated on.
|
||||
*
|
||||
* @var \DateTimeZone|string
|
||||
*/
|
||||
protected $timezone;
|
||||
|
||||
/**
|
||||
* The job dispatcher implementation.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Bus\Dispatcher
|
||||
*/
|
||||
protected $dispatcher;
|
||||
|
||||
/**
|
||||
* Create a new schedule instance.
|
||||
*
|
||||
* @param \DateTimeZone|string|null $timezone
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($timezone = null)
|
||||
{
|
||||
$this->timezone = $timezone;
|
||||
|
||||
if (! class_exists(Container::class)) {
|
||||
throw new RuntimeException(
|
||||
'A container implementation is required to use the scheduler. Please install the illuminate/container package.'
|
||||
);
|
||||
}
|
||||
|
||||
$container = Container::getInstance();
|
||||
|
||||
$this->eventMutex = $container->bound(EventMutex::class)
|
||||
? $container->make(EventMutex::class)
|
||||
: $container->make(CacheEventMutex::class);
|
||||
|
||||
$this->schedulingMutex = $container->bound(SchedulingMutex::class)
|
||||
? $container->make(SchedulingMutex::class)
|
||||
: $container->make(CacheSchedulingMutex::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new callback event to the schedule.
|
||||
*
|
||||
* @param string|callable $callback
|
||||
* @param array $parameters
|
||||
* @return \Illuminate\Console\Scheduling\CallbackEvent
|
||||
*/
|
||||
public function call($callback, array $parameters = [])
|
||||
{
|
||||
$this->events[] = $event = new CallbackEvent(
|
||||
$this->eventMutex, $callback, $parameters, $this->timezone
|
||||
);
|
||||
|
||||
return $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new Artisan command event to the schedule.
|
||||
*
|
||||
* @param string $command
|
||||
* @param array $parameters
|
||||
* @return \Illuminate\Console\Scheduling\Event
|
||||
*/
|
||||
public function command($command, array $parameters = [])
|
||||
{
|
||||
if (class_exists($command)) {
|
||||
$command = Container::getInstance()->make($command)->getName();
|
||||
}
|
||||
|
||||
return $this->exec(
|
||||
Application::formatCommandString($command), $parameters
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new job callback event to the schedule.
|
||||
*
|
||||
* @param object|string $job
|
||||
* @param string|null $queue
|
||||
* @param string|null $connection
|
||||
* @return \Illuminate\Console\Scheduling\CallbackEvent
|
||||
*/
|
||||
public function job($job, $queue = null, $connection = null)
|
||||
{
|
||||
return $this->call(function () use ($job, $queue, $connection) {
|
||||
$job = is_string($job) ? Container::getInstance()->make($job) : $job;
|
||||
|
||||
if ($job instanceof ShouldQueue) {
|
||||
$this->dispatchToQueue($job, $queue ?? $job->queue, $connection ?? $job->connection);
|
||||
} else {
|
||||
$this->dispatchNow($job);
|
||||
}
|
||||
})->name(is_string($job) ? $job : get_class($job));
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch the given job to the queue.
|
||||
*
|
||||
* @param object $job
|
||||
* @param string|null $queue
|
||||
* @param string|null $connection
|
||||
* @return void
|
||||
*/
|
||||
protected function dispatchToQueue($job, $queue, $connection)
|
||||
{
|
||||
if ($job instanceof Closure) {
|
||||
if (! class_exists(CallQueuedClosure::class)) {
|
||||
throw new RuntimeException(
|
||||
'To enable support for closure jobs, please install the illuminate/queue package.'
|
||||
);
|
||||
}
|
||||
|
||||
$job = CallQueuedClosure::create($job);
|
||||
}
|
||||
|
||||
$this->getDispatcher()->dispatch(
|
||||
$job->onConnection($connection)->onQueue($queue)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch the given job right now.
|
||||
*
|
||||
* @param object $job
|
||||
* @return void
|
||||
*/
|
||||
protected function dispatchNow($job)
|
||||
{
|
||||
$this->getDispatcher()->dispatchNow($job);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new command event to the schedule.
|
||||
*
|
||||
* @param string $command
|
||||
* @param array $parameters
|
||||
* @return \Illuminate\Console\Scheduling\Event
|
||||
*/
|
||||
public function exec($command, array $parameters = [])
|
||||
{
|
||||
if (count($parameters)) {
|
||||
$command .= ' '.$this->compileParameters($parameters);
|
||||
}
|
||||
|
||||
$this->events[] = $event = new Event($this->eventMutex, $command, $this->timezone);
|
||||
|
||||
return $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile parameters for a command.
|
||||
*
|
||||
* @param array $parameters
|
||||
* @return string
|
||||
*/
|
||||
protected function compileParameters(array $parameters)
|
||||
{
|
||||
return collect($parameters)->map(function ($value, $key) {
|
||||
if (is_array($value)) {
|
||||
return $this->compileArrayInput($key, $value);
|
||||
}
|
||||
|
||||
if (! is_numeric($value) && ! preg_match('/^(-.$|--.*)/i', $value)) {
|
||||
$value = ProcessUtils::escapeArgument($value);
|
||||
}
|
||||
|
||||
return is_numeric($key) ? $value : "{$key}={$value}";
|
||||
})->implode(' ');
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile array input for a command.
|
||||
*
|
||||
* @param string|int $key
|
||||
* @param array $value
|
||||
* @return string
|
||||
*/
|
||||
public function compileArrayInput($key, $value)
|
||||
{
|
||||
$value = collect($value)->map(function ($value) {
|
||||
return ProcessUtils::escapeArgument($value);
|
||||
});
|
||||
|
||||
if (Str::startsWith($key, '--')) {
|
||||
$value = $value->map(function ($value) use ($key) {
|
||||
return "{$key}={$value}";
|
||||
});
|
||||
} elseif (Str::startsWith($key, '-')) {
|
||||
$value = $value->map(function ($value) use ($key) {
|
||||
return "{$key} {$value}";
|
||||
});
|
||||
}
|
||||
|
||||
return $value->implode(' ');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the server is allowed to run this event.
|
||||
*
|
||||
* @param \Illuminate\Console\Scheduling\Event $event
|
||||
* @param \DateTimeInterface $time
|
||||
* @return bool
|
||||
*/
|
||||
public function serverShouldRun(Event $event, DateTimeInterface $time)
|
||||
{
|
||||
return $this->schedulingMutex->create($event, $time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all of the events on the schedule that are due.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Foundation\Application $app
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
public function dueEvents($app)
|
||||
{
|
||||
return collect($this->events)->filter->isDue($app);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all of the events on the schedule.
|
||||
*
|
||||
* @return \Illuminate\Console\Scheduling\Event[]
|
||||
*/
|
||||
public function events()
|
||||
{
|
||||
return $this->events;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify the cache store that should be used to store mutexes.
|
||||
*
|
||||
* @param string $store
|
||||
* @return $this
|
||||
*/
|
||||
public function useCache($store)
|
||||
{
|
||||
if ($this->eventMutex instanceof CacheAware) {
|
||||
$this->eventMutex->useStore($store);
|
||||
}
|
||||
|
||||
if ($this->schedulingMutex instanceof CacheAware) {
|
||||
$this->schedulingMutex->useStore($store);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the job dispatcher, if available.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Bus\Dispatcher
|
||||
*/
|
||||
protected function getDispatcher()
|
||||
{
|
||||
if ($this->dispatcher === null) {
|
||||
try {
|
||||
$this->dispatcher = Container::getInstance()->make(Dispatcher::class);
|
||||
} catch (BindingResolutionException $e) {
|
||||
throw new RuntimeException(
|
||||
'Unable to resolve the dispatcher from the service container. Please bind it or install the illuminate/bus package.',
|
||||
$e->getCode(), $e
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->dispatcher;
|
||||
}
|
||||
}
|
||||
42
vendor/laravel/framework/src/Illuminate/Console/Scheduling/ScheduleFinishCommand.php
vendored
Normal file
42
vendor/laravel/framework/src/Illuminate/Console/Scheduling/ScheduleFinishCommand.php
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Console\Scheduling;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class ScheduleFinishCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'schedule:finish {id} {code=0}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Handle the completion of a scheduled command';
|
||||
|
||||
/**
|
||||
* Indicates whether the command should be shown in the Artisan command list.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $hidden = true;
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @param \Illuminate\Console\Scheduling\Schedule $schedule
|
||||
* @return void
|
||||
*/
|
||||
public function handle(Schedule $schedule)
|
||||
{
|
||||
collect($schedule->events())->filter(function ($value) {
|
||||
return $value->mutexName() == $this->argument('id');
|
||||
})->each->callAfterCallbacksWithExitCode($this->laravel, $this->argument('code'));
|
||||
}
|
||||
}
|
||||
157
vendor/laravel/framework/src/Illuminate/Console/Scheduling/ScheduleRunCommand.php
vendored
Normal file
157
vendor/laravel/framework/src/Illuminate/Console/Scheduling/ScheduleRunCommand.php
vendored
Normal file
@@ -0,0 +1,157 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Console\Scheduling;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Console\Events\ScheduledTaskFailed;
|
||||
use Illuminate\Console\Events\ScheduledTaskFinished;
|
||||
use Illuminate\Console\Events\ScheduledTaskSkipped;
|
||||
use Illuminate\Console\Events\ScheduledTaskStarting;
|
||||
use Illuminate\Contracts\Debug\ExceptionHandler;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
use Illuminate\Support\Facades\Date;
|
||||
use Throwable;
|
||||
|
||||
class ScheduleRunCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'schedule:run';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Run the scheduled commands';
|
||||
|
||||
/**
|
||||
* The schedule instance.
|
||||
*
|
||||
* @var \Illuminate\Console\Scheduling\Schedule
|
||||
*/
|
||||
protected $schedule;
|
||||
|
||||
/**
|
||||
* The 24 hour timestamp this scheduler command started running.
|
||||
*
|
||||
* @var \Illuminate\Support\Carbon
|
||||
*/
|
||||
protected $startedAt;
|
||||
|
||||
/**
|
||||
* Check if any events ran.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $eventsRan = false;
|
||||
|
||||
/**
|
||||
* The event dispatcher.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Events\Dispatcher
|
||||
*/
|
||||
protected $dispatcher;
|
||||
|
||||
/**
|
||||
* The exception handler.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Debug\ExceptionHandler
|
||||
*/
|
||||
protected $handler;
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->startedAt = Date::now();
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @param \Illuminate\Console\Scheduling\Schedule $schedule
|
||||
* @param \Illuminate\Contracts\Events\Dispatcher $dispatcher
|
||||
* @param \Illuminate\Contracts\Debug\ExceptionHandler $handler
|
||||
* @return void
|
||||
*/
|
||||
public function handle(Schedule $schedule, Dispatcher $dispatcher, ExceptionHandler $handler)
|
||||
{
|
||||
$this->schedule = $schedule;
|
||||
$this->dispatcher = $dispatcher;
|
||||
$this->handler = $handler;
|
||||
|
||||
foreach ($this->schedule->dueEvents($this->laravel) as $event) {
|
||||
if (! $event->filtersPass($this->laravel)) {
|
||||
$this->dispatcher->dispatch(new ScheduledTaskSkipped($event));
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($event->onOneServer) {
|
||||
$this->runSingleServerEvent($event);
|
||||
} else {
|
||||
$this->runEvent($event);
|
||||
}
|
||||
|
||||
$this->eventsRan = true;
|
||||
}
|
||||
|
||||
if (! $this->eventsRan) {
|
||||
$this->info('No scheduled commands are ready to run.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the given single server event.
|
||||
*
|
||||
* @param \Illuminate\Console\Scheduling\Event $event
|
||||
* @return void
|
||||
*/
|
||||
protected function runSingleServerEvent($event)
|
||||
{
|
||||
if ($this->schedule->serverShouldRun($event, $this->startedAt)) {
|
||||
$this->runEvent($event);
|
||||
} else {
|
||||
$this->line('<info>Skipping command (has already run on another server):</info> '.$event->getSummaryForDisplay());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the given event.
|
||||
*
|
||||
* @param \Illuminate\Console\Scheduling\Event $event
|
||||
* @return void
|
||||
*/
|
||||
protected function runEvent($event)
|
||||
{
|
||||
$this->line('<info>Running scheduled command:</info> '.$event->getSummaryForDisplay());
|
||||
|
||||
$this->dispatcher->dispatch(new ScheduledTaskStarting($event));
|
||||
|
||||
$start = microtime(true);
|
||||
|
||||
try {
|
||||
$event->run($this->laravel);
|
||||
|
||||
$this->dispatcher->dispatch(new ScheduledTaskFinished(
|
||||
$event,
|
||||
round(microtime(true) - $start, 2)
|
||||
));
|
||||
|
||||
$this->eventsRan = true;
|
||||
} catch (Throwable $e) {
|
||||
$this->dispatcher->dispatch(new ScheduledTaskFailed($event, $e));
|
||||
|
||||
$this->handler->report($e);
|
||||
}
|
||||
}
|
||||
}
|
||||
26
vendor/laravel/framework/src/Illuminate/Console/Scheduling/SchedulingMutex.php
vendored
Normal file
26
vendor/laravel/framework/src/Illuminate/Console/Scheduling/SchedulingMutex.php
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Console\Scheduling;
|
||||
|
||||
use DateTimeInterface;
|
||||
|
||||
interface SchedulingMutex
|
||||
{
|
||||
/**
|
||||
* Attempt to obtain a scheduling mutex for the given event.
|
||||
*
|
||||
* @param \Illuminate\Console\Scheduling\Event $event
|
||||
* @param \DateTimeInterface $time
|
||||
* @return bool
|
||||
*/
|
||||
public function create(Event $event, DateTimeInterface $time);
|
||||
|
||||
/**
|
||||
* Determine if a scheduling mutex exists for the given event.
|
||||
*
|
||||
* @param \Illuminate\Console\Scheduling\Event $event
|
||||
* @param \DateTimeInterface $time
|
||||
* @return bool
|
||||
*/
|
||||
public function exists(Event $event, DateTimeInterface $time);
|
||||
}
|
||||
Reference in New Issue
Block a user