Repository: wasmerio/wasmer (language: rust)

Issue:
App cronjob config: add jitter percentage settings



Discussion / hints:

Fix patch:
diff --git a/docs/schema/generated/jsonschema/types/AppConfigV1.schema.json b/docs/schema/generated/jsonschema/types/AppConfigV1.schema.json
index 93bb57b884a..2d9499ebb6f 100644
--- a/docs/schema/generated/jsonschema/types/AppConfigV1.schema.json
+++ b/docs/schema/generated/jsonschema/types/AppConfigV1.schema.json
@@ -555,6 +555,24 @@
         "action": {
           "$ref": "#/definitions/JobAction"
         },
+        "jitter_percent_max": {
+          "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.",
+          "type": [
+            "integer",
+            "null"
+          ],
+          "format": "uint8",
+          "minimum": 0.0
+        },
+        "jitter_percent_min": {
+          "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.",
+          "type": [
+            "integer",
+            "null"
+          ],
+          "format": "uint8",
+          "minimum": 0.0
+        },
         "max_schedule_drift": {
           "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.",
           "anyOf": [
@@ -590,7 +608,8 @@
         "trigger": {
           "$ref": "#/definitions/JobTrigger"
         }
-      }
+      },
+      "additionalProperties": true
     },
     "JobAction": {
       "type": "object",
diff --git a/lib/config/src/app/job.rs b/lib/config/src/app/job.rs
index 08b12cfb665..8e5a208dd20 100644
--- a/lib/config/src/app/job.rs
+++ b/lib/config/src/app/job.rs
@@ -28,7 +28,39 @@ pub struct Job {
     #[serde(skip_serializing_if = "Option::is_none")]
     pub retries: Option<u32>,
 
+    /// Maximum percent of "jitter" to introduce between invocations.
+    ///
+    /// Value range: 0-100
+    ///
+    /// Jitter 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.
+    ///
+    /// See also [`Self::jitter_percent_min`] to set a minimum jitter.
+    #[serde(skip_serializing_if = "Option::is_none")]
+    pub jitter_percent_max: Option<u8>,
+
+    /// Minimum "jitter" to introduce between invocations.
+    ///
+    /// Value range: 0-100
+    ///
+    /// Jitter 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.
+    ///
+    /// If not specified while `jitter_percent_max` is, it will default to 10%.
+    ///
+    /// See also [`Self::jitter_percent_max`] to set a maximum jitter.
+    #[serde(skip_serializing_if = "Option::is_none")]
+    pub jitter_percent_min: Option<u8>,
+
     action: JobAction,
+
+    /// Additional unknown fields.
+    ///
+    /// Exists for forward compatibility for newly added fields.
+    #[serde(flatten)]
+    pub other: IndexMap<String, serde_json::Value>,
 }
 
 // We need this wrapper struct to enable this formatting:
@@ -257,6 +289,8 @@ mod tests {
             trigger: JobTrigger::Cron(parse_cron("0/2 12 * JAN-APR 2")),
             timeout: Some("1m".parse().unwrap()),
             max_schedule_drift: Some("2h".parse().unwrap()),
+            jitter_percent_max: None,
+            jitter_percent_min: None,
             retries: None,
             action: JobAction {
                 action: JobActionCase::Execute(super::ExecutableJob {
@@ -283,6 +317,7 @@ mod tests {
                     }]),
                 }),
             },
+            other: Default::default(),
         };
 
         let serialized = r#"


Test patch: