retry the remaining plain schedules with backon
This commit is contained in:
parent
e21a03d6ff
commit
ed76419be7
1 changed files with 132 additions and 64 deletions
|
|
@ -29,6 +29,7 @@
|
|||
use std::{future::Future, time::Duration};
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use backon::{BackoffBuilder as _, ConstantBuilder};
|
||||
use swarm_secret_client::{Error, SecretStore, client::DEFAULT_CERT_MOUNT, policy};
|
||||
|
||||
/// File holding the authority hives are issued from, as
|
||||
|
|
@ -111,12 +112,14 @@ where
|
|||
F: FnMut() -> Fut,
|
||||
Fut: Future<Output = Result<(), Unreachable>>,
|
||||
{
|
||||
let mut ticker = tokio::time::interval(interval);
|
||||
// `interval`'s first tick is immediate, and that pass is the one the caller
|
||||
// already ran before deciding to retry at all.
|
||||
ticker.tick().await;
|
||||
for n in 1..=attempts {
|
||||
ticker.tick().await;
|
||||
// One delay per attempt, waited before it: the pass the caller already ran
|
||||
// before deciding to retry at all is the attempt that needs no wait.
|
||||
let delays = ConstantBuilder::default()
|
||||
.with_delay(interval)
|
||||
.with_max_times(attempts as usize)
|
||||
.build();
|
||||
for (n, delay) in (1..).zip(delays) {
|
||||
tokio::time::sleep(delay).await;
|
||||
if attempt().await.is_ok() {
|
||||
return Some(n);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue