-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tool for printing out retry policy choices (#1997)
- Loading branch information
1 parent
eebdd20
commit 41d0fed
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} | ||
} |