Skip to content

Commit

Permalink
view: auto-restart view worker on error
Browse files Browse the repository at this point in the history
  • Loading branch information
hdevalence committed Feb 2, 2024
1 parent c1bb046 commit ccdffb2
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions crates/view/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,22 +384,20 @@ impl Worker {
}

pub async fn run(mut self) -> anyhow::Result<()> {
self.run_inner().await.map_err(|e| {
tracing::info!(?e, "view worker error");
self.error_slot
.lock()
.expect("no race conditions on worker error slot lock")
.replace(e);
anyhow::anyhow!("view worker error")
})
}

async fn run_inner(&mut self) -> anyhow::Result<()> {
// For now, this can be outside of the loop, because assets are only
// created at genesis. In the future, we'll want to have a way for
// clients to learn about assets as they're created.
self.sync().await?;
Ok(())
loop {
// Do a single sync run, recording any errors.
if let Err(e) = self.sync().await {
tracing::error!(?e, "view worker error");
self.error_slot
.lock()
.expect("mutex is not poisoned")
.replace(e);
}
// Sleep 10s (maybe later use exponential backoff?)
tokio::time::sleep(Duration::from_secs(10)).await;
// Clear the error slot before retrying.
*self.error_slot.lock().expect("mutex is not poisoned") = None;
}
}
}

Expand Down

0 comments on commit ccdffb2

Please sign in to comment.