Skip to content

Commit 6563ba6

Browse files
committed
formatting and editing
1 parent 964933d commit 6563ba6

5 files changed

Lines changed: 43 additions & 31 deletions

File tree

src/Illuminate/Console/Scheduling/CacheSchedulingMutex.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Illuminate\Console\Scheduling;
44

5-
use Illuminate\Support\Carbon;
5+
use DateTimeInterface;
66
use Illuminate\Contracts\Cache\Repository as Cache;
77

88
class CacheSchedulingMutex implements SchedulingMutex
@@ -29,24 +29,22 @@ public function __construct(Cache $cache)
2929
* Attempt to obtain a scheduling mutex for the given event.
3030
*
3131
* @param \Illuminate\Console\Scheduling\Event $event
32-
* @param \Illuminate\Support\Carbon $time
32+
* @param \DateTimeInterface $time
3333
* @return bool
3434
*/
35-
public function create(Event $event, Carbon $time)
35+
public function create(Event $event, DateTimeInterface $time)
3636
{
37-
return $this->cache->add(
38-
$event->mutexName().$time->format('Hi'), true, 60
39-
);
37+
return $this->cache->add($event->mutexName().$time->format('Hi'), true, 60);
4038
}
4139

4240
/**
4341
* Determine if a scheduling mutex exists for the given event.
4442
*
4543
* @param \Illuminate\Console\Scheduling\Event $event
46-
* @param \Illuminate\Support\Carbon $time
44+
* @param \DateTimeInterface $time
4745
* @return bool
4846
*/
49-
public function exists(Event $event, Carbon $time)
47+
public function exists(Event $event, DateTimeInterface $time)
5048
{
5149
return $this->cache->has($event->mutexName().$time->format('Hi'));
5250
}

src/Illuminate/Console/Scheduling/Event.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class Event
6565
public $withoutOverlapping = false;
6666

6767
/**
68-
* Indicates if the command should only be allowed to run on one server each cron expression.
68+
* Indicates if the command should only be allowed to run on one server for each cron expression.
6969
*
7070
* @var bool
7171
*/

src/Illuminate/Console/Scheduling/Schedule.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Illuminate\Console\Scheduling;
44

5+
use DateTimeInterface;
56
use Illuminate\Support\Carbon;
67
use Illuminate\Console\Application;
78
use Illuminate\Container\Container;
@@ -121,18 +122,6 @@ public function exec($command, array $parameters = [])
121122
return $event;
122123
}
123124

124-
/**
125-
* Determine if the server is allowed to run this event.
126-
*
127-
* @param \Illuminate\Console\Scheduling\Event $event
128-
* @param \Illuminate\Support\Carbon $time
129-
* @return bool
130-
*/
131-
public function allowServerToRun(Event $event, Carbon $time)
132-
{
133-
return $this->schedulingMutex->create($event, $time);
134-
}
135-
136125
/**
137126
* Compile parameters for a command.
138127
*
@@ -154,6 +143,18 @@ protected function compileParameters(array $parameters)
154143
})->implode(' ');
155144
}
156145

146+
/**
147+
* Determine if the server is allowed to run this event.
148+
*
149+
* @param \Illuminate\Console\Scheduling\Event $event
150+
* @param \DateTimeInterface $time
151+
* @return bool
152+
*/
153+
public function serverShouldRun(Event $event, DateTimeInterface $time)
154+
{
155+
return $this->schedulingMutex->create($event, $time);
156+
}
157+
157158
/**
158159
* Get all of the events on the schedule that are due.
159160
*

src/Illuminate/Console/Scheduling/ScheduleRunCommand.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,7 @@ public function handle()
7070
}
7171

7272
if ($event->onOneServer) {
73-
if ($this->schedule->allowServerToRun($event, $this->startedAt)) {
74-
$this->runEvent($event);
75-
} else {
76-
$this->line('<info>Skipping command (already run on another server):</info> '.$event->getSummaryForDisplay());
77-
}
73+
$this->runSingleServerEvent($event);
7874
} else {
7975
$this->runEvent($event);
8076
}
@@ -87,6 +83,21 @@ public function handle()
8783
}
8884
}
8985

86+
/**
87+
* Run the given single server event.
88+
*
89+
* @param \Illuminate\Support\Collection $event
90+
* @return void
91+
*/
92+
protected function runSingleServerEvent($event)
93+
{
94+
if ($this->schedule->serverShouldRun($event, $this->startedAt)) {
95+
$this->runEvent($event);
96+
} else {
97+
$this->line('<info>Skipping command (has already run on another server):</info> '.$event->getSummaryForDisplay());
98+
}
99+
}
100+
90101
/**
91102
* Run the given event.
92103
*
@@ -96,7 +107,9 @@ public function handle()
96107
protected function runEvent($event)
97108
{
98109
$this->line('<info>Running scheduled command:</info> '.$event->getSummaryForDisplay());
110+
99111
$event->run($this->laravel);
112+
100113
$this->eventsRan = true;
101114
}
102115
}

src/Illuminate/Console/Scheduling/SchedulingMutex.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@
22

33
namespace Illuminate\Console\Scheduling;
44

5-
use Illuminate\Support\Carbon;
5+
use DateTimeInterface;
66

77
interface SchedulingMutex
88
{
99
/**
1010
* Attempt to obtain a scheduling mutex for the given event.
1111
*
1212
* @param \Illuminate\Console\Scheduling\Event $event
13-
* @param \Illuminate\Support\Carbon $time
13+
* @param \DateTimeInterface $time
1414
* @return bool
1515
*/
16-
public function create(Event $event, Carbon $time);
16+
public function create(Event $event, DateTimeInterface $time);
1717

1818
/**
1919
* Determine if a scheduling mutex exists for the given event.
2020
*
2121
* @param \Illuminate\Console\Scheduling\Event $event
22-
* @param \Illuminate\Support\Carbon $time
22+
* @param \DateTimeInterface $time
2323
* @return bool
2424
*/
25-
public function exists(Event $event, Carbon $time);
25+
public function exists(Event $event, DateTimeInterface $time);
2626
}

0 commit comments

Comments
 (0)