-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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] Add sometimeDaily()
to scheduler
#52331
Conversation
I don't know if what I'm thinking makes sense, but for me, it would be more appropriate to call this |
It will happen once daily. Each call is essentially a macro for |
Personally, I prefer closures with dailyAt method like this
|
I like it, my only suggestion would be maybe an optional parameter to customize how far apart they are scheduled in case you have longer running tasks or tasks you want to space out more for some other reason. |
This is how I wished the normal The only project I wouldn't use it on is one that has a peak usage time. Makes me wish there was a dailyBetween() along the same lines |
Ooh, I do like that! It'd be nice to schedule all these "cleanup" style tasks during slow hours only. I might take a crack at tweaking this tomorrow! |
I like the idea, I would have imagined something that would balance out the commands during the day evenly depending on the number of commands that want to be balanced. May I suggest something like this? Schedule::command('artisan:inspire')->duringTheDay();
Schedule::command('artisan:info')->duringTheDay();
Schedule::command('migrate')->duringTheHour();
Schedule::command('db:seed')->duringTheHour();
Schedule::command('db:prune')->duringTheHour(); Which would:
WDYTAI? |
I wonder if this would be a bit better like: Schedule::call(fn)->hourly()->nextVacancy();
Schedule::call(fn)->daily()->nextVacancy();
Schedule::call(fn)->weekly()->nextVacancy();
Schedule::call(fn)->quarterly()->nextVacancy(after: 5); // 5 minutes after next quarterly scheduled task |
@taylorotwell I shied away from something like that because it would involve tracking more data across the scheduler. If you're OK with a bigger refactor, I'm up for taking a stab at it. The way I see it, for something like that to work we'd either need to make the existing schedule available to future tasks, or track a bunch of data about the last/next scheduled task of each type. |
I dunno - I'm close to thinking this is a neat idea but I can't decide if it's really going to be that trustworthy in practice. The 5 minute time feels a bit arbitrary and isn't configurable and doesn't help you at all if most of your commands take longer than that. |
Often times you have scheduled commands that you want to run every day, but you don't particularly care when during the day they run. For apps that have many scheduled tasks, this can unintentionally cause a huge spike in command execution every midnight—the default for
daily()
.This PR introduces a
sometimeDaily()
method that incrementally schedules tasks 5 minutes apart from each other throughout the day:If, somehow, you manage to fill out every 5-minute increment, it will reset back to midnight and start again.