Skip to content

Commit

Permalink
Exponential backoff for some retries
Browse files Browse the repository at this point in the history
  • Loading branch information
benthecarman committed Jul 3, 2024
1 parent 35d4744 commit f2ef760
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion mutiny-core/src/hermes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ impl<S: MutinyStorage> HermesClient<S> {
let current_address_check_clone = self.current_address.clone();
let first_federation = self.get_first_federation().await.clone();
utils::spawn(async move {
let mut count = 1;
loop {
if stop_check_clone.load(Ordering::Relaxed) {
break;
Expand Down Expand Up @@ -263,7 +264,10 @@ impl<S: MutinyStorage> HermesClient<S> {
}
};

utils::sleep(1_000).await;
// exponential backoff
let sleep_time = std::cmp::min(1_000 * (2_i32.pow(count)), 60_000);
utils::sleep(sleep_time).await;
count += 1;
}
});

Expand Down
6 changes: 5 additions & 1 deletion mutiny-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1482,12 +1482,16 @@ impl<S: MutinyStorage> MutinyWallet<S> {
let self_clone = self.clone();
utils::spawn(async move {
// keep trying until it succeeds
let mut count = 1;
loop {
match self_clone.sync_nostr().await {
Ok(_) => break,
Err(e) => {
log_error!(self_clone.logger, "Failed to sync nostr: {e}");
sleep(5_000).await;

// exponential backoff
let sleep_time = std::cmp::min(1_000 * (2_i32.pow(count)), 60_000);
sleep(sleep_time).await;
}
}

Expand Down

0 comments on commit f2ef760

Please sign in to comment.