Skip to content

Commit

Permalink
formatting and editing
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Nov 30, 2017
1 parent 964933d commit 6563ba6
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 31 deletions.
14 changes: 6 additions & 8 deletions src/Illuminate/Console/Scheduling/CacheSchedulingMutex.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Console/Scheduling/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
25 changes: 13 additions & 12 deletions src/Illuminate/Console/Scheduling/Schedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Illuminate\Console\Scheduling;

use DateTimeInterface;
use Illuminate\Support\Carbon;
use Illuminate\Console\Application;
use Illuminate\Container\Container;
Expand Down Expand Up @@ -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.
*
Expand All @@ -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.
*
Expand Down
23 changes: 18 additions & 5 deletions src/Illuminate/Console/Scheduling/ScheduleRunCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,7 @@ public function handle()
}

if ($event->onOneServer) {
if ($this->schedule->allowServerToRun($event, $this->startedAt)) {
$this->runEvent($event);
} else {
$this->line('<info>Skipping command (already run on another server):</info> '.$event->getSummaryForDisplay());
}
$this->runSingleServerEvent($event);
} else {
$this->runEvent($event);
}
Expand All @@ -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('<info>Skipping command (has already run on another server):</info> '.$event->getSummaryForDisplay());
}
}

/**
* Run the given event.
*
Expand All @@ -96,7 +107,9 @@ public function handle()
protected function runEvent($event)
{
$this->line('<info>Running scheduled command:</info> '.$event->getSummaryForDisplay());

$event->run($this->laravel);

$this->eventsRan = true;
}
}
10 changes: 5 additions & 5 deletions src/Illuminate/Console/Scheduling/SchedulingMutex.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@

namespace Illuminate\Console\Scheduling;

use Illuminate\Support\Carbon;
use DateTimeInterface;

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);
}

0 comments on commit 6563ba6

Please sign in to comment.