From b32c7682f0a84619a6d1845516a6a1829fa0c59b Mon Sep 17 00:00:00 2001 From: Owen Jacobson Date: Fri, 27 Feb 2026 16:41:37 -0500 Subject: Move failed push handling inside of the web push publisher. I want push publication to be "fire and forget," and ultimately also for it to be asynchronous and retriable. To facilitate that, the caller needs to be insulated from the final outcome of publishing a push message. I've opted to preserve the `Failure` possibility, but any delivery issues are now handled inside the publisher. --- src/test/webpush.rs | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) (limited to 'src/test/webpush.rs') diff --git a/src/test/webpush.rs b/src/test/webpush.rs index 55caf19..656f66a 100644 --- a/src/test/webpush.rs +++ b/src/test/webpush.rs @@ -1,11 +1,11 @@ use std::{ any::Any, - collections::{HashMap, HashSet}, + collections::HashSet, mem, sync::{Arc, Mutex, MutexGuard}, }; -use web_push::{PartialVapidSignatureBuilder, SubscriptionInfo, WebPushError}; +use web_push::{PartialVapidSignatureBuilder, SubscriptionInfo}; use crate::{error::failed::Failed, push::Publish}; @@ -15,7 +15,6 @@ pub struct Client(Arc>); #[derive(Default)] struct ClientInner { sent: Vec, - planned_failures: HashMap, } impl Client { @@ -33,35 +32,23 @@ impl Client { let sent = &mut self.inner().sent; mem::take(sent) } - - pub fn fail_next(&self, subscription_info: &SubscriptionInfo, err: WebPushError) { - let planned_failures = &mut self.inner().planned_failures; - planned_failures.insert(subscription_info.clone(), err); - } } #[async_trait::async_trait] impl Publish for Client { - async fn publish<'s, M>( + async fn publish( &self, message: M, _: &PartialVapidSignatureBuilder, - subscriptions: impl IntoIterator + Send, - ) -> Result, Failed> + subscriptions: impl IntoIterator + Send, + ) -> Result<(), Failed> where M: Send + 'static, { let mut inner = self.inner(); - let message: Box = Box::new(message); - let mut recipients = HashSet::new(); - let mut failures = Vec::new(); - for subscription in subscriptions { - recipients.insert(subscription.clone()); - if let Some(err) = inner.planned_failures.remove(subscription) { - failures.push((subscription, err)); - } - } + let message: Box = Box::new(message); + let recipients = subscriptions.into_iter().cloned().collect(); let publication = Publication { message, @@ -69,7 +56,7 @@ impl Publish for Client { }; inner.sent.push(publication); - Ok(failures) + Ok(()) } } -- cgit v1.2.3