feat: Exponential backoff

This commit is contained in:
Elijah McMorris 2024-09-19 01:51:13 -07:00
parent 200d5a0377
commit 091bb50a7e
Signed by: NexVeridian
SSH key fingerprint: SHA256:bsA1SKZxuEcEVHAy3gY1HUeM5ykRJl0U0kQHQn0hMg8
8 changed files with 24 additions and 15 deletions

View file

@ -38,7 +38,7 @@ async fn main() -> Result<(), Error> {
None::<Surreal<Client>>,
reader,
Some(pb.clone()),
1_000,
100,
1_000,
)
.await?;

View file

@ -75,6 +75,7 @@ impl CreateVersion {
tokio::spawn(async move {
let mut retries = 0;
loop {
match dbo {
Some(ref db) => {
@ -93,11 +94,12 @@ impl CreateVersion {
}
}
if retries >= 60 * 10 {
// Exponential backoff with cap at 60 seconds
if retries == 30 {
panic!("Failed to create entities, too many retries");
}
sleep(Duration::from_millis(250) * 2_u32.pow(retries.min(8))).await;
retries += 1;
sleep(Duration::from_millis(250)).await;
}
})
}