Skip to content

Commit 81bd316

Browse files
committed
feat(config): Add cronjob jitter settings
1 parent 75a3ddd commit 81bd316

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

Diff for: docs/schema/generated/jsonschema/types/AppConfigV1.schema.json

+20-1
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,24 @@
555555
"action": {
556556
"$ref": "#/definitions/JobAction"
557557
},
558+
"jitter_percent_max": {
559+
"description": "Maximum percent of \"jitter\" to introduce between invocations.\n\nValue range: 0-100\n\nJitter is used to spread out jobs over time. The calculation works by multiplying the time between invocations by a random amount, and taking the percentage of that random amount.\n\nSee also [`Self::jitter_percent_min`] to set a minimum jitter.",
560+
"type": [
561+
"integer",
562+
"null"
563+
],
564+
"format": "uint8",
565+
"minimum": 0.0
566+
},
567+
"jitter_percent_min": {
568+
"description": "Minimum \"jitter\" to introduce between invocations.\n\nValue range: 0-100\n\nJitter is used to spread out jobs over time. The calculation works by multiplying the time between invocations by a random amount, and taking the percentage of that random amount.\n\nIf not specified while `jitter_percent_max` is, it will default to 10%.\n\nSee also [`Self::jitter_percent_max`] to set a maximum jitter.",
569+
"type": [
570+
"integer",
571+
"null"
572+
],
573+
"format": "uint8",
574+
"minimum": 0.0
575+
},
558576
"max_schedule_drift": {
559577
"description": "Don't start job if past the due time by this amount, instead opting to wait for the next instance of it to be triggered.",
560578
"anyOf": [
@@ -590,7 +608,8 @@
590608
"trigger": {
591609
"$ref": "#/definitions/JobTrigger"
592610
}
593-
}
611+
},
612+
"additionalProperties": true
594613
},
595614
"JobAction": {
596615
"type": "object",

Diff for: lib/config/src/app/job.rs

+35
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,39 @@ pub struct Job {
2828
#[serde(skip_serializing_if = "Option::is_none")]
2929
pub retries: Option<u32>,
3030

31+
/// Maximum percent of "jitter" to introduce between invocations.
32+
///
33+
/// Value range: 0-100
34+
///
35+
/// Jitter is used to spread out jobs over time.
36+
/// The calculation works by multiplying the time between invocations
37+
/// by a random amount, and taking the percentage of that random amount.
38+
///
39+
/// See also [`Self::jitter_percent_min`] to set a minimum jitter.
40+
#[serde(skip_serializing_if = "Option::is_none")]
41+
pub jitter_percent_max: Option<u8>,
42+
43+
/// Minimum "jitter" to introduce between invocations.
44+
///
45+
/// Value range: 0-100
46+
///
47+
/// Jitter is used to spread out jobs over time.
48+
/// The calculation works by multiplying the time between invocations
49+
/// by a random amount, and taking the percentage of that random amount.
50+
///
51+
/// If not specified while `jitter_percent_max` is, it will default to 10%.
52+
///
53+
/// See also [`Self::jitter_percent_max`] to set a maximum jitter.
54+
#[serde(skip_serializing_if = "Option::is_none")]
55+
pub jitter_percent_min: Option<u8>,
56+
3157
action: JobAction,
58+
59+
/// Additional unknown fields.
60+
///
61+
/// Exists for forward compatibility for newly added fields.
62+
#[serde(flatten)]
63+
pub other: IndexMap<String, serde_json::Value>,
3264
}
3365

3466
// We need this wrapper struct to enable this formatting:
@@ -257,6 +289,8 @@ mod tests {
257289
trigger: JobTrigger::Cron(parse_cron("0/2 12 * JAN-APR 2")),
258290
timeout: Some("1m".parse().unwrap()),
259291
max_schedule_drift: Some("2h".parse().unwrap()),
292+
jitter_percent_max: None,
293+
jitter_percent_min: None,
260294
retries: None,
261295
action: JobAction {
262296
action: JobActionCase::Execute(super::ExecutableJob {
@@ -283,6 +317,7 @@ mod tests {
283317
}]),
284318
}),
285319
},
320+
other: Default::default(),
286321
};
287322

288323
let serialized = r#"

0 commit comments

Comments
 (0)