diff options
| author | Owen Jacobson <owen@grimoire.ca> | 2026-02-27 16:41:37 -0500 |
|---|---|---|
| committer | Owen Jacobson <owen@grimoire.ca> | 2026-02-27 18:15:33 -0500 |
| commit | b32c7682f0a84619a6d1845516a6a1829fa0c59b (patch) | |
| tree | fad8bf5bd8eb628253611f0b3d1a91febe3b9266 /src/push/app.rs | |
| parent | 6ab0f42250294e38e8da6a48260ff83544a6be9a (diff) | |
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.
Diffstat (limited to 'src/push/app.rs')
| -rw-r--r-- | src/push/app.rs | 48 |
1 files changed, 3 insertions, 45 deletions
diff --git a/src/push/app.rs b/src/push/app.rs index f7846a6..1983055 100644 --- a/src/push/app.rs +++ b/src/push/app.rs @@ -1,6 +1,6 @@ use p256::ecdsa::VerifyingKey; use sqlx::SqlitePool; -use web_push::{SubscriptionInfo, WebPushError}; +use web_push::SubscriptionInfo; use super::repo::Provider as _; use crate::{ @@ -78,7 +78,7 @@ impl<P> Push<P> where P: Publish, { - pub async fn ping(&self, recipient: &Login) -> Result<(), PushError> { + pub async fn ping(&self, recipient: &Login) -> Result<(), Failed> { let mut tx = self.db.begin().await.fail(db::failed::BEGIN)?; let signer = tx @@ -99,44 +99,10 @@ where // we need to write. tx.commit().await.fail(db::failed::COMMIT)?; - let failures = self - .publisher + self.publisher .publish(Heartbeat::Heartbeat, &signer, &subscriptions) .await .fail("Failed to send push message")?; - - if !failures.is_empty() { - let mut tx = self.db.begin().await.fail(db::failed::BEGIN)?; - // Note that data integrity guarantees from the original transaction to read - // subscriptions may no longer be valid now. Time has passed. Depending on how slow - // delivering push notifications is, potentially a _lot_ of time has passed. - - for (sub, err) in &failures { - match err { - // I _think_ this is the complete set of permanent failures. See - // <https://docs.rs/web-push/latest/web_push/enum.WebPushError.html> for a complete - // list. - WebPushError::Unauthorized(_) - | WebPushError::InvalidUri - | WebPushError::EndpointNotValid(_) - | WebPushError::EndpointNotFound(_) - | WebPushError::InvalidCryptoKeys - | WebPushError::MissingCryptoKeys => { - tx.push() - .unsubscribe(sub) - .await - .fail("Failed to unsubscribe after permanent push message rejection")?; - } - _ => (), - } - } - - tx.commit().await.fail(db::failed::COMMIT)?; - - return Err(PushError::Delivery( - failures.into_iter().map(|(_, err)| err).collect(), - )); - } Ok(()) } } @@ -153,11 +119,3 @@ pub enum SubscribeError { #[error(transparent)] Failed(#[from] Failed), } - -#[derive(Debug, thiserror::Error)] -pub enum PushError { - #[error("push message delivery failures: {0:?}")] - Delivery(Vec<WebPushError>), - #[error(transparent)] - Failed(#[from] Failed), -} |
