Skip to content

[7.x] Add "every 2 / 3 / 4 / 6 hours" methods to scheduler - #33393

Merged
taylorotwell merged 1 commit into
laravel:7.xfrom
SjorsO:more-cron
Jun 30, 2020
Merged

[7.x] Add "every 2 / 3 / 4 / 6 hours" methods to scheduler#33393
taylorotwell merged 1 commit into
laravel:7.xfrom
SjorsO:more-cron

Conversation

@SjorsO

@SjorsO SjorsO commented Jun 30, 2020

Copy link
Copy Markdown
Contributor

This PR, just like #33379, adds more useful methods to the scheduler:

  • everyTwoHours()
  • everyThreeHours()
  • everyFourHours()
  • everySixHours()

These new methods go alongside the currently available hourly and twiceDaily methods (twiceDaily is essentially everyTwelveHours).

I believe scheduling cron jobs at these intervals is common enough that they deserve dedicated methods. You can currently only achieve the same behavior by writing a custom cron expression:

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

// or, with this PR

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

It is easy to make mistakes when writing your own cron expressions. For example, if you by mistake write * */2 * * *, your job will be running 60 times every 2 hours.

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.

2 participants