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

[Scheduler] randomize a cron schedule #49806

Closed
wants to merge 1 commit into from

Conversation

vtsykun
Copy link
Contributor

@vtsykun vtsykun commented Mar 25, 2023

Q A
Branch? 6.3
Bug fix? no
New feature? yes
Deprecations? no
Tickets -
License MIT
Doc PR -

This PR resolve problem of running things at midnight or once an hour at XX:00, to avoid loading peaks every hour/minutes.
Example usage

return (new Schedule())
    ->add(RecurringMessage::cron('*/10 * * * *', new \stdClass(), 120))

Selection_1375

@fabpot
Copy link
Member

fabpot commented Apr 23, 2023

Closing in favor of #49792.

@fabpot fabpot closed this Apr 23, 2023
fabpot added a commit that referenced this pull request May 10, 2023
This PR was merged into the 6.3 branch.

Discussion
----------

[Scheduler] add `JitterTrigger`

| Q             | A
| ------------- | ---
| Branch?       | 6.4
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | #49806
| License       | MIT
| Doc PR        | n/a

I think this is what `@vtsykun` was trying to accomplish with #49806. FreeBSD has a `-jitter` option that does the same thing so I think there's precedent. From the (https://man.freebsd.org/cgi/man.cgi?cron):

> -j	jitter
>	     Enable time jitter.  Prior	to executing commands, cron will sleep
	     a random number of	seconds	in the range from 0 to jitter.	~This
	     will not affect superuser jobs (see -J).~  A value for jitter must
	     be	between	0 and 60 inclusive.  Default is	0, which effectively
	     disables time jitter.
>	     This option can help to smooth down system	load spikes during mo-
	     ments when	a lot of jobs are likely to start at once, e.g., at
	     the beginning of the first	minute of each hour.

Usage:

```php
// defaults to 0-60 seconds
$schedule->add(RecurringMessage::cron('`@daily`', $message1)->withJitter());

// customize the max seconds (0-30)
$schedule->add(RecurringMessage::cron('`@daily`', $message1)->withJitter(30));
```

Commits
-------

b0d984b [Scheduler] add `JitterTrigger`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants