Skip to content

Commit 0c34031

Browse files
Qqwyisomorpheme
authored andcommitted
Add .is_healthy() method to the Opsqueue Consumer client
1 parent ddd3c97 commit 0c34031

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

opsqueue/src/consumer/client.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,7 @@ impl OuterClient {
123123
}
124124

125125
async fn ensure_initialized(&self) {
126-
let inner = self.0.load();
127-
if inner.is_none() || inner.as_ref().is_some_and(|c| !c.is_healthy()) {
126+
if !self.is_healthy() {
128127
let client = self.initialize().await;
129128
self.0.store(Some(Arc::new(client)));
130129
}
@@ -138,6 +137,14 @@ impl OuterClient {
138137
.await
139138
.expect("Infinite retries should never return Err")
140139
}
140+
141+
/// When `false` is returned, the next call to the client will attempt to restore the connection.
142+
///
143+
/// This function can be used to propagate healthiness info to a consumer service.
144+
pub fn is_healthy(&self) -> bool {
145+
let inner = self.0.load();
146+
inner.as_ref().is_some_and(|c| c.is_healthy())
147+
}
141148
}
142149

143150
// TOOD: Set max retries to `None`;

0 commit comments

Comments
 (0)