[11.x] Introduce Schedule Grouping#53427
Conversation
|
Nice! Glad to see this revived. |
|
Hope this will be merged. I think about this every time I call |
|
I'd prefer a syntax like this: Schedule::group(function () {
Schedule::command('command-one');
Schedule::command('command-two');
})
->runInBackground()
->withoutOverlapping()
->everyMinute(); |
|
Thanks for the suggestion, @rodrigopedra! In my view, the suggested syntax makes the chaining feel a bit less clean and slightly harder to follow. Keeping these configurations at the start helps highlight the group’s behavior, improving readability and clarity overall. That said, if there’s strong preference for this approach, I’m definitely open to revisiting the implementation. |
|
My preference is that it would be more inline with the route group feature, mentioned as inspiration for this feature. Also, in my opinion, it is more declarative. But let's wait for the maintainer's opinion. Other than that, I think this is a great addition! |
I agree! This is more inlined with how Laravel handles fluent route method. |
|
@Rizky92 @rodrigopedra I looked into the route group feature again, and it seems that using the syntax you suggested doesn’t apply the group options to the routes. For example: Route::group([], function () {
Route::get('/test', fn () => 'Admin Dashboard')->name('home');
})
->name('admin.') // doesn’t affect routes
->prefix('/admin'); // doesn’t affect routesInstead, it needs to be structured like this: Route::name('admin.')
->prefix('/admin')
->group(function () {
Route::get('/test', fn () => 'Admin Dashboard')->name('home');
});This setup aligns with my suggested syntax. But let’s see what the maintainers think before making any changes. 🙏 |
|
Having the group at end is fine to me. On the other hand, your usage example has an empty That is what I find misaligned with the route group feature. |
|
@istiak-tridip Really would love to finally get this in the framework in some form. I am in agreement that consistency with the documented Route group syntax would be awesome where |
|
@taylorotwell I can think of two ways to implement the
Let me know which direction you'd prefer! |
How about extracting the relevant method to a trait and use that trait on both classes? That way, you get auto completion without duplicating the methods? |
|
@morloderex Thanks for the reminder! That’s actually what I had planned to do; I just forgot to mention it. I’ve updated my previous reply to reflect this. |
|
@taylorotwell I've taken a closer look at the codebase to explore implementing the syntax through the second method if we go that route. I've identified some potential side effects with this approach. For example, end users could write: Schedule::runInBackground()->command('command-one');While that seems fine (similar to routes), issues arise with the For instance, Schedule::call('command-one')->runInBackground(); // Throws `RuntimeException`Allowing A solution could be to only allow What do you think? |
Wondering if it would work by just making |
|
@morloderex That approach is possible, but it would completely change the current behavior, which may cause existing tests to fail and go against end-users' existing expectations. It might also be considered a breaking change, though I'm not entirely sure. For now, it may be best to wait for feedback from @taylorotwell or other maintainers. |
|
@stevebauman @taylorotwell I’ve updated the implementation to follow Here’s an example of the new Schedule::everyMinute()
->runInBackground()
->withoutOverlapping()
->group(function () {
Schedule::command('command-one');
Schedule::command('command-two');
Schedule::command('command-three')->everyTenMinutes();
});Additionally, this implementation allows users to declare schedules similarly to Route, like this: Schedule::hourly()->command('inspire'); |
stevebauman
left a comment
There was a problem hiding this comment.
Just nits left. Everything LGTM! 👍
We will see what the Laravel team thinks.
Co-authored-by: Steve Bauman <steven_bauman@outlook.com>
|
Thanks @istiak-tridip! |
|
Strange but I get when I use group with Schedule::runInBackground()
->withoutOverlapping()
->everyMinute()
->group(function () {
Schedule::command(FetchSchedule::class);
});If I comment |
|
@decadence I was able to reproduce the issue and have submitted a bug fix in PR #53553. Could you please test the fix and share your feedback on the PR? Thanks! |
|
@istiak-tridip I think I found another bug with I have these events: Schedule::runInBackground()
->group(function () {
Schedule::dailyAt("09:00")
->group(function () {
Schedule::command(ConnectVps::class);
});
Schedule::command(ActiveDocuments::class)
->everyTenMinutes();
});As you can see This code works as expected: Schedule::runInBackground()
->group(function () {
Schedule::dailyAt("09:00")
->group(function () {
Schedule::command(ConnectVps::class);
});
});
Schedule::command(ActiveDocuments::class)
->everyTenMinutes(); |

Description
This PR introduces a new feature allowing related schedules to be grouped, similar to the
Route::groupmethod.With this addition, developers can configure multiple schedules collectively, reducing the need for repetitive configuration of individual schedules.
Looking forward to your feedback. Thanks for all the great work that you guys do! 😍
Current Behavior
With This PR
Individual schedules can override group configurations as needed:
Nested grouping is also supported:
Past similar proposals: #49832 #48046