Skip to content

[Scheduler] add JitterTrigger #50270

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

Merged
merged 1 commit into from
May 10, 2023
Merged

Conversation

kbond
Copy link
Member

@kbond kbond commented May 8, 2023

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:

// 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));

@fabpot
Copy link
Member

fabpot commented May 9, 2023

I'm wondering if we should do this at a higher level. Having a jitter is probably a common need for most triggers.

@kbond
Copy link
Member Author

kbond commented May 9, 2023

Yes, I was thinking that also.

@kbond kbond force-pushed the scheduler-cron-jitter branch from 79aa0a4 to ae996e8 Compare May 9, 2023 15:22
@kbond kbond changed the title [Scheduler] add CronExpressionTrigger::jitter() [Scheduler] add JitterTrigger May 9, 2023
@kbond
Copy link
Member Author

kbond commented May 9, 2023

I'm wondering if we should do this at a higher level. Having a jitter is probably a common need for most triggers.

I've updated this PR to add a JitterTrigger that can add a jitter to any trigger. Also, added RecurringMessage::withJitter() to help with DX (description updated to show usage).

@kbond kbond force-pushed the scheduler-cron-jitter branch 2 times, most recently from ebf05fb to 6cec1d6 Compare May 9, 2023 15:38
Co-authored-by: Uladzimir Tsykun <tsykun314@gmail.com>
@kbond kbond force-pushed the scheduler-cron-jitter branch from 6cec1d6 to b0d984b Compare May 9, 2023 15:40
@fabpot
Copy link
Member

fabpot commented May 10, 2023

Thank you @kbond.

@fabpot fabpot merged commit 3b29817 into symfony:6.3 May 10, 2023
@kbond kbond deleted the scheduler-cron-jitter branch May 10, 2023 12:58
@fabpot fabpot mentioned this pull request May 13, 2023
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