Skip to content

Commit

Permalink
[11.x] Improve schedule group behaviors (#53641)
Browse files Browse the repository at this point in the history
* throw exception

* introduce `resetFrequency` method

* formatting

---------

Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
istiak-tridip and taylorotwell authored Nov 25, 2024
1 parent 00c4b68 commit cfa26fb
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Illuminate/Console/Scheduling/Schedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class Schedule
/**
* The attributes to pass to the event.
*
* @var \Illuminate\Console\Scheduling\PendingEventAttributes
* @var \Illuminate\Console\Scheduling\PendingEventAttributes|null
*/
protected $attributes;

Expand Down Expand Up @@ -287,9 +287,15 @@ public function exec($command, array $parameters = [])
*
* @param \Illuminate\Console\Scheduling\Event $event
* @return void
*
* @throws \RuntimeException
*/
public function group(Closure $events)
{
if ($this->attributes === null) {
throw new RuntimeException('Invoke an attribute method such as Schedule::daily() before defining a schedule group.');
}

$this->groupStack[] = $this->attributes;

$events($this);
Expand All @@ -308,7 +314,7 @@ protected function mergePendingAttributes(Event $event)
if (isset($this->attributes)) {
$this->attributes->mergeAttributes($event);

unset($this->attributes);
$this->attributes = null;
}

if (! empty($this->groupStack)) {
Expand Down

0 comments on commit cfa26fb

Please sign in to comment.