8000 [Scheduler] randomize a cron schedule by vtsykun · Pull Request #49806 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

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

@vtsykun vtsykun force-pushed the feature/add-random-delay branch from d06e0ff to 2bb84c2 Compare March 26, 2023 21:40
@vtsykun vtsykun force-pushed the feature/add-random-delay branch from 2bb84c2 to 9b8e44c Compare March 26, 2023 21:42
@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.

4 participants

0