Skip to content

Commit dc3ad68

Browse files
authored
add every 2/3/4/6 hours method to scheduler (#33393)
1 parent 116b508 commit dc3ad68

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

src/Illuminate/Console/Scheduling/ManagesFrequencies.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,50 @@ public function hourlyAt($offset)
174174
return $this->spliceIntoPosition(1, $offset);
175175
}
176176

177+
/**
178+
* Schedule the event to run every two hours.
179+
*
180+
* @return $this
181+
*/
182+
public function everyTwoHours()
183+
{
184+
return $this->spliceIntoPosition(1, 0)
185+
->spliceIntoPosition(2, '*/2');
186+
}
187+
188+
/**
189+
* Schedule the event to run every three hours.
190+
*
191+
* @return $this
192+
*/
193+
public function everyThreeHours()
194+
{
195+
return $this->spliceIntoPosition(1, 0)
196+
->spliceIntoPosition(2, '*/3');
197+
}
198+
199+
/**
200+
* Schedule the event to run every four hours.
201+
*
202+
* @return $this
203+
*/
204+
public function everyFourHours()
205+
{
206+
return $this->spliceIntoPosition(1, 0)
207+
->spliceIntoPosition(2, '*/4');
208+
}
209+
210+
/**
211+
* Schedule the event to run every six hours.
212+
*
213+
* @return $this
214+
*/
215+
public function everySixHours()
216+
{
217+
return $this->spliceIntoPosition(1, 0)
218+
->spliceIntoPosition(2, '*/6');
219+
}
220+
177221
/**
178222
* Schedule the event to run daily.
179223
*

tests/Console/Scheduling/FrequencyTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ public function testOverrideWithHourly()
5353
$this->assertSame('15,30,45 * * * *', $this->event->hourlyAt([15, 30, 45])->getExpression());
5454
}
5555

56+
public function testHourly()
57+
{
58+
$this->assertSame('0 */2 * * *', $this->event->everyTwoHours()->getExpression());
59+
$this->assertSame('0 */3 * * *', $this->event->everyThreeHours()->getExpression());
60+
$this->assertSame('0 */4 * * *', $this->event->everyFourHours()->getExpression());
61+
$this->assertSame('0 */6 * * *', $this->event->everySixHours()->getExpression());
62+
}
63+
5664
public function testMonthlyOn()
5765
{
5866
$this->assertSame('0 15 4 * *', $this->event->monthlyOn(4, '15:00')->getExpression());

0 commit comments

Comments
 (0)