-
Notifications
You must be signed in to change notification settings - Fork 11k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[11.x] Introduce Schedule Grouping #53427
base: 11.x
Are you sure you want to change the base?
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 routes Instead, 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this idea! 👍
@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'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just nits left. Everything LGTM! 👍
We will see what the Laravel team thinks.
Co-authored-by: Steve Bauman <[email protected]>
Description
This PR introduces a new feature allowing related schedules to be grouped, similar to the
Route::group
method.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