Skip to content

Commit

Permalink
Make delayed workloads look better
Browse files Browse the repository at this point in the history
  • Loading branch information
rescrv committed Dec 2, 2024
1 parent dcc5522 commit a018807
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
8 changes: 4 additions & 4 deletions rust/load/examples/workload-json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ fn main() {
),
(
1.0,
Workload::Delay(
chrono::DateTime::parse_from_rfc3339("2021-01-01T00:00:00+00:00").unwrap(),
Box::new(Workload::Nop),
),
Workload::Delay {
after: chrono::DateTime::parse_from_rfc3339("2021-01-01T00:00:00+00:00").unwrap(),
wrap: Box::new(Workload::Nop),
},
),
]);
println!("{}", serde_json::to_string_pretty(&w).unwrap());
Expand Down
28 changes: 16 additions & 12 deletions rust/load/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,10 @@ pub enum Workload {
#[serde(rename = "hybrid")]
Hybrid(Vec<(f64, Workload)>),
#[serde(rename = "delay")]
Delay(chrono::DateTime<chrono::FixedOffset>, Box<Workload>),
Delay {
after: chrono::DateTime<chrono::FixedOffset>,
wrap: Box<Workload>,
},
}

impl Workload {
Expand All @@ -227,7 +230,7 @@ impl Workload {
workload.resolve_by_name(workloads)?;
}
}
Workload::Delay(_, w) => w.resolve_by_name(workloads)?,
Workload::Delay { after: _, wrap } => wrap.resolve_by_name(workloads)?,
}
Ok(())
}
Expand Down Expand Up @@ -285,7 +288,7 @@ impl Workload {
"miscalculation of total hybrid probabilities".to_string(),
)))
}
Workload::Delay(_, w) => Box::pin(w.step(client, data_set, guac)).await,
Workload::Delay { after: _, wrap } => Box::pin(wrap.step(client, data_set, guac)).await,
}
}

Expand All @@ -296,7 +299,7 @@ impl Workload {
Workload::Get(_) => true,
Workload::Query(_) => true,
Workload::Hybrid(hybrid) => hybrid.iter().any(|(_, w)| w.is_active()),
Workload::Delay(after, w) => chrono::Utc::now() >= *after && w.is_active(),
Workload::Delay { after, wrap } => chrono::Utc::now() >= *after && wrap.is_active(),
}
}
}
Expand Down Expand Up @@ -788,10 +791,10 @@ mod tests {
[
1.0,
{
"delay": [
"2021-01-01T00:00:00Z",
"nop"
]
"delay": {
"after": "2021-01-01T00:00:00Z",
"wrap": "nop"
}
}
]
]
Expand All @@ -817,10 +820,11 @@ mod tests {
),
(
1.0,
Workload::Delay(
chrono::DateTime::parse_from_rfc3339("2021-01-01T00:00:00+00:00").unwrap(),
Box::new(Workload::Nop),
),
Workload::Delay {
after: chrono::DateTime::parse_from_rfc3339("2021-01-01T00:00:00+00:00")
.unwrap(),
wrap: Box::new(Workload::Nop),
},
),
]);
assert_eq!(json, serde_json::to_string_pretty(&workload).unwrap());
Expand Down

0 comments on commit a018807

Please sign in to comment.