Skip to content

Commit

Permalink
add tool for printing out retry policy choices (#1997)
Browse files Browse the repository at this point in the history
  • Loading branch information
davepacheco authored Nov 30, 2022
1 parent eebdd20 commit 41d0fed
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions common/examples/backoff-print.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

//! Show example retry intervals and times for the internal service policy
use omicron_common::backoff;
use omicron_common::backoff::Backoff;

fn main() {
let mut policy = backoff::retry_policy_long();
let mut total_duration = std::time::Duration::from_secs(0);
loop {
let nmin = total_duration.as_secs() / 60;
let nsecs = total_duration.as_secs() % 60;
let nmillis = total_duration.as_millis() % 1000;
print!("at T={:3}m{:02}.{:03}s: ", nmin, nsecs, nmillis);

if let Some(next) = policy.next_backoff() {
let nmin = next.as_secs() / 60;
let nsecs = next.as_secs() % 60;
let nmillis = next.as_millis() % 1000;
println!("wait {:3}m{:02}.{:03}s", nmin, nsecs, nmillis);
total_duration = total_duration + next;

if nmin >= 60 {
break;
}
}
}
}

0 comments on commit 41d0fed

Please sign in to comment.