mirror of
https://github.com/modrinth/code.git
synced 2026-08-27 10:04:52 +00:00
redo error handling in xredis
This commit is contained in:
+3
-14
@@ -3,11 +3,10 @@ use std::sync::atomic::{AtomicBool, Ordering};
|
||||
|
||||
use dashmap::DashMap;
|
||||
use dashmap::mapref::entry::Entry;
|
||||
use eyre::{Result, WrapErr};
|
||||
use tokio::sync::Notify;
|
||||
use tokio::time::{Instant, timeout_at};
|
||||
|
||||
use crate::Error;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub(in crate::cache) struct LockCoordinator {
|
||||
locks: Arc<DashMap<String, Arc<LockState>>>,
|
||||
@@ -76,10 +75,7 @@ pub(in crate::cache) struct LockWaiter {
|
||||
}
|
||||
|
||||
impl LockWaiter {
|
||||
pub(in crate::cache) async fn wait(
|
||||
self,
|
||||
deadline: Instant,
|
||||
) -> Result<(), Error> {
|
||||
pub(in crate::cache) async fn wait(self, deadline: Instant) -> Result<()> {
|
||||
loop {
|
||||
if self.state.released.load(Ordering::Acquire) {
|
||||
return Ok(());
|
||||
@@ -94,7 +90,7 @@ impl LockWaiter {
|
||||
|
||||
timeout_at(deadline, notified)
|
||||
.await
|
||||
.map_err(|_| lock_timeout())?;
|
||||
.wrap_err("waiting for local Redis cache lock")?;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -112,10 +108,3 @@ impl LockState {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn lock_timeout() -> Error {
|
||||
Error::LocalCacheTimeout {
|
||||
released: 0,
|
||||
total: 1,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user