Skip to content

Commit 8df026d

Browse files
committed
core: Add a backoff for repolling failed offchain data sources
1 parent ccd276e commit 8df026d

File tree

1 file changed

+16
-7
lines changed
  • core/src/polling_monitor

1 file changed

+16
-7
lines changed

core/src/polling_monitor/mod.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,9 @@ where
169169
debug!(logger, "not found on polling"; "object_id" => id.to_string());
170170

171171
metrics.not_found.inc();
172-
queue.push_back(id);
172+
173+
// We'll try again after a backoff.
174+
backoff(id, &queue, &mut backoffs);
173175
}
174176

175177
// Error polling, log it and push the id to the back of the queue.
@@ -182,12 +184,7 @@ where
182184
// Requests that return errors could mean there is a permanent issue with
183185
// fetching the given item, or could signal the endpoint is overloaded.
184186
// Either way a backoff makes sense.
185-
let queue = queue.cheap_clone();
186-
let backoff = backoffs.next_backoff(id.clone());
187-
graph::spawn(async move {
188-
backoff.await;
189-
queue.push_back(id);
190-
});
187+
backoff(id, &queue, &mut backoffs);
191188
}
192189
}
193190
}
@@ -197,6 +194,18 @@ where
197194
PollingMonitor { queue }
198195
}
199196

197+
fn backoff<ID>(id: ID, queue: &Arc<Queue<ID>>, backoffs: &mut Backoffs<ID>)
198+
where
199+
ID: Eq + Hash + Clone + Send + 'static,
200+
{
201+
let queue = queue.cheap_clone();
202+
let backoff = backoffs.next_backoff(id.clone());
203+
graph::spawn(async move {
204+
backoff.await;
205+
queue.push_back(id);
206+
});
207+
}
208+
200209
/// Handle for adding objects to be monitored.
201210
pub struct PollingMonitor<ID> {
202211
queue: Arc<Queue<ID>>,

0 commit comments

Comments
 (0)