From 6563ba65b65106198095f1d61f91e0ec542e98dd Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 30 Nov 2017 08:17:04 -0600 Subject: [PATCH] formatting and editing --- .../Scheduling/CacheSchedulingMutex.php | 14 +++++------ src/Illuminate/Console/Scheduling/Event.php | 2 +- .../Console/Scheduling/Schedule.php | 25 ++++++++++--------- .../Console/Scheduling/ScheduleRunCommand.php | 23 +++++++++++++---- .../Console/Scheduling/SchedulingMutex.php | 10 ++++---- 5 files changed, 43 insertions(+), 31 deletions(-) diff --git a/src/Illuminate/Console/Scheduling/CacheSchedulingMutex.php b/src/Illuminate/Console/Scheduling/CacheSchedulingMutex.php index f2540d3b3d67..c865f4c63187 100644 --- a/src/Illuminate/Console/Scheduling/CacheSchedulingMutex.php +++ b/src/Illuminate/Console/Scheduling/CacheSchedulingMutex.php @@ -2,7 +2,7 @@ namespace Illuminate\Console\Scheduling; -use Illuminate\Support\Carbon; +use DateTimeInterface; use Illuminate\Contracts\Cache\Repository as Cache; class CacheSchedulingMutex implements SchedulingMutex @@ -29,24 +29,22 @@ public function __construct(Cache $cache) * Attempt to obtain a scheduling mutex for the given event. * * @param \Illuminate\Console\Scheduling\Event $event - * @param \Illuminate\Support\Carbon $time + * @param \DateTimeInterface $time * @return bool */ - public function create(Event $event, Carbon $time) + public function create(Event $event, DateTimeInterface $time) { - return $this->cache->add( - $event->mutexName().$time->format('Hi'), true, 60 - ); + return $this->cache->add($event->mutexName().$time->format('Hi'), true, 60); } /** * Determine if a scheduling mutex exists for the given event. * * @param \Illuminate\Console\Scheduling\Event $event - * @param \Illuminate\Support\Carbon $time + * @param \DateTimeInterface $time * @return bool */ - public function exists(Event $event, Carbon $time) + public function exists(Event $event, DateTimeInterface $time) { return $this->cache->has($event->mutexName().$time->format('Hi')); } diff --git a/src/Illuminate/Console/Scheduling/Event.php b/src/Illuminate/Console/Scheduling/Event.php index 889bfbc7de2a..89f9c99408fe 100644 --- a/src/Illuminate/Console/Scheduling/Event.php +++ b/src/Illuminate/Console/Scheduling/Event.php @@ -65,7 +65,7 @@ class Event public $withoutOverlapping = false; /** - * Indicates if the command should only be allowed to run on one server each cron expression. + * Indicates if the command should only be allowed to run on one server for each cron expression. * * @var bool */ diff --git a/src/Illuminate/Console/Scheduling/Schedule.php b/src/Illuminate/Console/Scheduling/Schedule.php index 76872d6c4e56..a4bdbfe1cbd4 100644 --- a/src/Illuminate/Console/Scheduling/Schedule.php +++ b/src/Illuminate/Console/Scheduling/Schedule.php @@ -2,6 +2,7 @@ namespace Illuminate\Console\Scheduling; +use DateTimeInterface; use Illuminate\Support\Carbon; use Illuminate\Console\Application; use Illuminate\Container\Container; @@ -121,18 +122,6 @@ public function exec($command, array $parameters = []) return $event; } - /** - * Determine if the server is allowed to run this event. - * - * @param \Illuminate\Console\Scheduling\Event $event - * @param \Illuminate\Support\Carbon $time - * @return bool - */ - public function allowServerToRun(Event $event, Carbon $time) - { - return $this->schedulingMutex->create($event, $time); - } - /** * Compile parameters for a command. * @@ -154,6 +143,18 @@ protected function compileParameters(array $parameters) })->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. * diff --git a/src/Illuminate/Console/Scheduling/ScheduleRunCommand.php b/src/Illuminate/Console/Scheduling/ScheduleRunCommand.php index 5e5528aacb18..fd1c58d9f551 100644 --- a/src/Illuminate/Console/Scheduling/ScheduleRunCommand.php +++ b/src/Illuminate/Console/Scheduling/ScheduleRunCommand.php @@ -70,11 +70,7 @@ public function handle() } if ($event->onOneServer) { - if ($this->schedule->allowServerToRun($event, $this->startedAt)) { - $this->runEvent($event); - } else { - $this->line('Skipping command (already run on another server): '.$event->getSummaryForDisplay()); - } + $this->runSingleServerEvent($event); } else { $this->runEvent($event); } @@ -87,6 +83,21 @@ public function handle() } } + /** + * Run the given single server event. + * + * @param \Illuminate\Support\Collection $event + * @return void + */ + protected function runSingleServerEvent($event) + { + if ($this->schedule->serverShouldRun($event, $this->startedAt)) { + $this->runEvent($event); + } else { + $this->line('Skipping command (has already run on another server): '.$event->getSummaryForDisplay()); + } + } + /** * Run the given event. * @@ -96,7 +107,9 @@ public function handle() protected function runEvent($event) { $this->line('Running scheduled command: '.$event->getSummaryForDisplay()); + $event->run($this->laravel); + $this->eventsRan = true; } } diff --git a/src/Illuminate/Console/Scheduling/SchedulingMutex.php b/src/Illuminate/Console/Scheduling/SchedulingMutex.php index 097c5106ca56..ab4e87da5557 100644 --- a/src/Illuminate/Console/Scheduling/SchedulingMutex.php +++ b/src/Illuminate/Console/Scheduling/SchedulingMutex.php @@ -2,7 +2,7 @@ namespace Illuminate\Console\Scheduling; -use Illuminate\Support\Carbon; +use DateTimeInterface; interface SchedulingMutex { @@ -10,17 +10,17 @@ interface SchedulingMutex * Attempt to obtain a scheduling mutex for the given event. * * @param \Illuminate\Console\Scheduling\Event $event - * @param \Illuminate\Support\Carbon $time + * @param \DateTimeInterface $time * @return bool */ - public function create(Event $event, Carbon $time); + public function create(Event $event, DateTimeInterface $time); /** * Determine if a scheduling mutex exists for the given event. * * @param \Illuminate\Console\Scheduling\Event $event - * @param \Illuminate\Support\Carbon $time + * @param \DateTimeInterface $time * @return bool */ - public function exists(Event $event, Carbon $time); + public function exists(Event $event, DateTimeInterface $time); }