diff --git a/src/Illuminate/Console/Scheduling/Schedule.php b/src/Illuminate/Console/Scheduling/Schedule.php index 30994a28a851..83dd524fb21a 100644 --- a/src/Illuminate/Console/Scheduling/Schedule.php +++ b/src/Illuminate/Console/Scheduling/Schedule.php @@ -200,15 +200,23 @@ public function job($job, $queue = null, $connection = null) : $job::class; } - return $this->name($jobName)->call(function () use ($job, $queue, $connection) { - $job = is_string($job) ? Container::getInstance()->make($job) : $job; + $this->events[] = $event = new CallbackEvent( + $this->eventMutex, function () use ($job, $queue, $connection) { + $job = is_string($job) ? Container::getInstance()->make($job) : $job; + + if ($job instanceof ShouldQueue) { + $this->dispatchToQueue($job, $queue ?? $job->queue, $connection ?? $job->connection); + } else { + $this->dispatchNow($job); + } + }, [], $this->timezone + ); - if ($job instanceof ShouldQueue) { - $this->dispatchToQueue($job, $queue ?? $job->queue, $connection ?? $job->connection); - } else { - $this->dispatchNow($job); - } - }); + $event->name($jobName); + + $this->mergePendingAttributes($event); + + return $event; } /** diff --git a/tests/Integration/Console/Scheduling/ScheduleGroupTest.php b/tests/Integration/Console/Scheduling/ScheduleGroupTest.php index 5ff2dd451f08..1e8cff36ba2b 100644 --- a/tests/Integration/Console/Scheduling/ScheduleGroupTest.php +++ b/tests/Integration/Console/Scheduling/ScheduleGroupTest.php @@ -7,6 +7,7 @@ use Illuminate\Console\Scheduling\Schedule as ScheduleClass; use Illuminate\Support\Carbon; use Illuminate\Support\Facades\Schedule; +use Illuminate\Tests\Console\Fixtures\JobToTestWithSchedule; use Orchestra\Testbench\TestCase; use PHPUnit\Framework\Attributes\DataProvider; @@ -195,4 +196,21 @@ public function testGroupedPendingEventAttribute() $this->assertSame('0 1 * * 1-5', $events[1]->expression); $this->assertSame('* * * * 1-5', $events[2]->expression); } + + public function testGroupedPendingEventAttributesWithoutOverlapping() + { + $schedule = new ScheduleClass; + $schedule->weekdays()->withoutOverlapping()->group(function ($schedule) { + $schedule->command('inspire')->at('14:00'); // this is event, not pending attribute + $schedule->at('03:00')->command('inspire'); // this is pending attribute + $schedule->command('inspire'); // this goes back to group pending attribute + $schedule->job(JobToTestWithSchedule::class)->at('04:00'); // this is pending attribute + }); + + $events = $schedule->events(); + $this->assertSame('0 14 * * 1-5', $events[0]->expression); + $this->assertSame('0 3 * * 1-5', $events[1]->expression); + $this->assertSame('* * * * 1-5', $events[2]->expression); + $this->assertSame('0 4 * * 1-5', $events[3]->expression); + } }