This commit is contained in:
Brandon Thomas committed 2026-03-25 17:10:21 -04:00
1 parent 9152b61cca
commit 7e8ca70153
3 files changed
+12 -13

No files matched your search

+2 -5
View File
@@ -59,9 +59,7 @@ impl Pager {
&self,
notification: NotificationDetails,
) -> Result<PageSentResult, PagerError> {
self.client.send_page(&notification)
.await
.map_err(PagerError::Service)
self.client.send_page(&notification).await
}
/// Enqueue a page to be sent by the background worker thread.
@@ -75,8 +73,7 @@ impl Pager {
let queue = self.queue.as_ref()
.ok_or(PagerSystemError::QueueFull)?;
let dropped = queue.push(notification)
.map_err(PagerError::System)?;
let dropped = queue.push(notification)?;
if let Some(dropped) = dropped {
log::warn!("Pager queue overflow: dropped '{}'", dropped.summary);
+4 -3
View File
@@ -5,6 +5,7 @@ use rootly_client::requests::create_alert::create_alert::{
create_alert, CreateAlertArgs,
};
use crate::error::pager_error::PagerError;
use crate::error::pager_service_error::PagerServiceError;
use crate::notification::notification_details::NotificationDetails;
@@ -59,7 +60,7 @@ impl PagerClient {
}
/// Send a page immediately.
pub async fn send_page(&self, notification: &NotificationDetails) -> Result<PageSentResult, PagerServiceError> {
pub async fn send_page(&self, notification: &NotificationDetails) -> Result<PageSentResult, PagerError> {
match &self.client_config {
PagerClientConfig::Rootly { .. } => self.send_page_via_rootly(notification).await,
}
@@ -68,7 +69,7 @@ impl PagerClient {
async fn send_page_via_rootly(
&self,
notification: &NotificationDetails,
) -> Result<PageSentResult, PagerServiceError> {
) -> Result<PageSentResult, PagerError> {
let PagerClientConfig::Rootly {
api_key,
alert_urgency_id,
@@ -118,7 +119,7 @@ impl PagerClient {
}
Err(err) => {
error!("Failed to send page via Rootly: {}", err);
Err(PagerServiceError::RootlyError(err))
Err(PagerError::Service(PagerServiceError::RootlyError(err)))
}
}
}
@@ -3,6 +3,7 @@ use std::sync::{Arc, Mutex, Condvar};
use log::warn;
use crate::error::pager_error::PagerError;
use crate::error::pager_system_error::PagerSystemError;
use crate::notification::notification_details::NotificationDetails;
@@ -35,7 +36,7 @@ impl PagerWorkerMessageQueue {
///
/// If the queue is full, the oldest item is dropped and a warning is logged.
/// Returns `Ok(Some(summary))` if an old item was evicted, `Ok(None)` otherwise.
pub fn push(&self, notification: NotificationDetails) -> Result<Option<NotificationDetails>, PagerSystemError> {
pub fn push(&self, notification: NotificationDetails) -> Result<Option<NotificationDetails>, PagerError> {
let mut queue = self.inner.lock()
.map_err(|e| PagerSystemError::MutexPoisoned(format!("push: {}", e)))?;
@@ -57,7 +58,7 @@ impl PagerWorkerMessageQueue {
/// Block until at least one item is available, then drain all items.
///
/// Returns an error if the mutex is poisoned.
pub fn wait_and_drain(&self) -> Result<Vec<NotificationDetails>, PagerSystemError> {
pub fn wait_and_drain(&self) -> Result<Vec<NotificationDetails>, PagerError> {
let mut queue = self.inner.lock()
.map_err(|e| PagerSystemError::MutexPoisoned(format!("wait_and_drain lock: {}", e)))?;
@@ -71,7 +72,7 @@ impl PagerWorkerMessageQueue {
}
/// Non-blocking drain of all currently queued items.
pub fn drain_available(&self) -> Result<Vec<NotificationDetails>, PagerSystemError> {
pub fn drain_available(&self) -> Result<Vec<NotificationDetails>, PagerError> {
let mut queue = self.inner.lock()
.map_err(|e| PagerSystemError::MutexPoisoned(format!("drain_available: {}", e)))?;
Ok(queue.drain(..).collect())
@@ -84,13 +85,13 @@ impl PagerWorkerMessageQueue {
self.condvar.notify_all();
}
pub fn len(&self) -> Result<usize, PagerSystemError> {
pub fn len(&self) -> Result<usize, PagerError> {
let queue = self.inner.lock()
.map_err(|e| PagerSystemError::MutexPoisoned(format!("len: {}", e)))?;
Ok(queue.len())
}
pub fn is_empty(&self) -> Result<bool, PagerSystemError> {
pub fn is_empty(&self) -> Result<bool, PagerError> {
Ok(self.len()? == 0)
}
}