Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions src/Illuminate/Console/Scheduling/Schedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
18 changes: 18 additions & 0 deletions tests/Integration/Console/Scheduling/ScheduleGroupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
}