Skip to content

Commit

Permalink
Merge pull request #1235 from MutinyWallet/exp-backoff
Browse files Browse the repository at this point in the history
Exponential backoff for some retries
  • Loading branch information
benthecarman authored Jul 3, 2024
2 parents 3bc9ad9 + c63d218 commit 34078eb
Show file tree
Hide file tree
Showing 2 changed files with 11 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
7 changes: 6 additions & 1 deletion mutiny-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1482,12 +1482,17 @@ 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;
count += 1;
}
}

Expand Down

0 comments on commit 34078eb

Please sign in to comment.