Skip to content
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

[7.x] Add "every 2 / 3 / 4 minutes" methods to scheduler #33379

Merged
merged 1 commit into from
Jun 29, 2020
Merged

[7.x] Add "every 2 / 3 / 4 minutes" methods to scheduler #33379

merged 1 commit into from
Jun 29, 2020

Conversation

SjorsO
Copy link
Contributor

@SjorsO SjorsO commented Jun 29, 2020

This PR adds the following methods to the scheduler:

  • everyTwoMinutes()
  • everyThreeMinutes()
  • everyFourMinutes()

These new methods go alongside the currently available everyMinute and everyFiveMinutes methods.

I need these methods for an application that syncs data from a legacy system. We have to sync the data "in real time" (as in, so that it feels like "real time"). Using everyMinute seems like overkill, and might overload their server. On the other hand, everyFiveMinutes doesn't feel "real time" enough. Being able to schedule the sync every 2 or 3 minutes would be perfect.

Scheduling jobs that should run very often is a common use-case. These new methods give developers more choice in exactly how often.

@browner12
Copy link
Contributor

I think you may be better off running a custom expression for this:

->cron('* */2 * * *');
->cron('* */3 * * *');
->cron('* */4 * * *');
php

@thomasm789
Copy link
Contributor

thomasm789 commented Jun 29, 2020

I agree with browner12. Although it wouldn't necessarily be an issue including more methods. Your immediate problem can be resolved using a custom cron schedule.

https://laravel.com/docs/7.x/scheduling#schedule-frequency-options

@devcircus
Copy link
Contributor

I believe this is macroable as well

@SjorsO
Copy link
Contributor Author

SjorsO commented Jun 29, 2020

As @browner12 said, you can currently achieve the same result by using a custom cron expression. But considering how cryptic the cron expression syntax is, you should probably always add a comment so the rest of your team can understand what's going on:

$schedule->job(SyncSomething::class)->cron('*/2 * * * *'); // every 2 minutes

// or, with this PR

$schedule->job(SyncSomething::class)->everyTwoMinutes();

@taylorotwell taylorotwell merged commit 5c841b3 into laravel:7.x Jun 29, 2020
@seriquynh
Copy link
Contributor

I think too many proxy methods don't make sense and the framework core code becomes more and more giant.

@ragingdave
Copy link
Contributor

Boy I wish I would have seen this, rather than adding all those proxy methods, I would have suggested using everyMinute with a param that could optionally change the frequency instead. That way everyTwoMinutes could have just been everyMinute(2) instead of all these added methods...

@SjorsO
Copy link
Contributor Author

SjorsO commented Jul 1, 2020

Boy I wish I would have seen this, rather than adding all those proxy methods, I would have suggested using everyMinute with a param that could optionally change the frequency instead. That way everyTwoMinutes could have just been everyMinute(2) instead of all these added methods...

See #33380

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants