Skip to content

Commit

Permalink
fix(plugin): add more logs while retry
Browse files Browse the repository at this point in the history
We should be a little bit more verbose when we try
a request.

Signed-off-by: Vincenzo Palazzo <[email protected]>
  • Loading branch information
vincenzopalazzo committed Sep 11, 2023
1 parent 30f0ce4 commit 4d0d5b4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion folgore-esplora/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ impl<T: Clone, S: RecoveryStrategy> FolgoreBackend<T> for Esplora<S> {
"block": null,
});

let chain_tip = self.client.get_height().map_err(|err| error!("{err}"))?;
let chain_tip = self
.recovery_strategy
.apply(|| self.client.get_height().map_err(|err| error!("{err}")))
.map_err(|err| error!("{err}"))?;
if height > chain_tip.into() {
let resp = json!({
"blockhash": null,
Expand Down
6 changes: 6 additions & 0 deletions folgore-plugin/src/recovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ impl RecoveryStrategy for TimeoutRetry {
{
let mut result = cb();
while result.is_err() {
log::info!(
"running into retry logic due a request failing. Time `{}` waiting `{}` secs",
*self.times.borrow(),
self.timeout.borrow().as_secs()
);
if self.times.borrow().eq(&4) {
log::info!(
"we try {} times the request but the error persist",
Expand All @@ -71,6 +76,7 @@ impl RecoveryStrategy for TimeoutRetry {
}
// This help us to keep the self not mutable.
std::thread::sleep(*self.timeout.borrow());
log::info!("Waiting timeout end");
// now we increase the timeout
self.timeout.borrow_mut().mul_assign(2);
self.times.borrow_mut().add_assign(1);
Expand Down

0 comments on commit 4d0d5b4

Please sign in to comment.