refactor(pushd): add non-panic error handling to all queue consumers

This commit is contained in:
izzy
2025-05-13 10:41:03 +01:00
parent 01e0f9e558
commit 2aff76c369
14 changed files with 460 additions and 184 deletions

View File

@@ -1,6 +1,7 @@
use std::{borrow::Cow, collections::BTreeMap, io::Cursor};
use amqprs::{channel::Channel as AmqpChannel, consumer::AsyncConsumer, BasicProperties, Deliver};
use anyhow::{anyhow, Result};
use async_trait::async_trait;
use base64::{
engine::{self},
@@ -122,20 +123,16 @@ impl ApnsOutboundConsumer {
Ok(ApnsOutboundConsumer { db, client })
}
}
#[allow(unused_variables)]
#[async_trait]
impl AsyncConsumer for ApnsOutboundConsumer {
async fn consume(
async fn consume_event(
&mut self,
channel: &AmqpChannel,
deliver: Deliver,
basic_properties: BasicProperties,
_channel: &AmqpChannel,
_deliver: Deliver,
_basic_properties: BasicProperties,
content: Vec<u8>,
) {
let content = String::from_utf8(content).unwrap();
let payload: PayloadToService = serde_json::from_str(content.as_str()).unwrap();
) -> Result<()> {
let content = String::from_utf8(content)?;
let payload: PayloadToService = serde_json::from_str(content.as_str())?;
let payload_options = NotificationOptions {
apns_id: None,
@@ -159,7 +156,7 @@ impl AsyncConsumer for ApnsOutboundConsumer {
alert.from_user.username, alert.from_user.discriminator
)))
.clone()
.unwrap(),
.ok_or_else(|| anyhow!("missing name"))?,
)];
let apn_payload = Payload {
@@ -205,7 +202,7 @@ impl AsyncConsumer for ApnsOutboundConsumer {
alert.accepted_user.username, alert.accepted_user.discriminator
)))
.clone()
.unwrap(),
.ok_or_else(|| anyhow!("missing name"))?,
)];
let apn_payload = Payload {
@@ -355,5 +352,27 @@ impl AsyncConsumer for ApnsOutboundConsumer {
}
}
}
Ok(())
}
}
#[allow(unused_variables)]
#[async_trait]
impl AsyncConsumer for ApnsOutboundConsumer {
async fn consume(
&mut self,
channel: &AmqpChannel,
deliver: Deliver,
basic_properties: BasicProperties,
content: Vec<u8>,
) {
if let Err(err) = self
.consume_event(channel, deliver, basic_properties, content)
.await
{
revolt_config::capture_anyhow(&err);
eprintln!("Failed to process APN event: {err:?}");
}
}
}