mirror of
https://git.asonix.dog/asonix/relay.git
synced 2024-11-28 20:41:33 +00:00
Break notify loop on error
This commit is contained in:
parent
19857a77f1
commit
8fb810b5bf
1 changed files with 25 additions and 26 deletions
|
@ -6,10 +6,7 @@ use crate::{
|
||||||
use activitystreams::primitives::XsdAnyUri;
|
use activitystreams::primitives::XsdAnyUri;
|
||||||
use actix::clock::{delay_for, Duration};
|
use actix::clock::{delay_for, Duration};
|
||||||
use bb8_postgres::tokio_postgres::{tls::NoTls, AsyncMessage, Config};
|
use bb8_postgres::tokio_postgres::{tls::NoTls, AsyncMessage, Config};
|
||||||
use futures::{
|
use futures::stream::{poll_fn, StreamExt};
|
||||||
future::ready,
|
|
||||||
stream::{poll_fn, StreamExt},
|
|
||||||
};
|
|
||||||
use log::{debug, error, warn};
|
use log::{debug, error, warn};
|
||||||
use std::{collections::HashMap, sync::Arc};
|
use std::{collections::HashMap, sync::Arc};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
@ -68,32 +65,34 @@ impl Notifier {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut stream = poll_fn(move |cx| conn.poll_message(cx)).filter_map(|m| match m {
|
let mut stream = poll_fn(move |cx| conn.poll_message(cx));
|
||||||
Ok(AsyncMessage::Notification(n)) => {
|
|
||||||
debug!("Handling Notification, {:?}", n);
|
|
||||||
ready(Some(n))
|
|
||||||
}
|
|
||||||
Ok(AsyncMessage::Notice(e)) => {
|
|
||||||
debug!("Handling Notice, {:?}", e);
|
|
||||||
ready(None)
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
debug!("Handling Error, {:?}", e);
|
|
||||||
ready(None)
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
debug!("Handling rest");
|
|
||||||
ready(None)
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
while let Some(n) = stream.next().await {
|
loop {
|
||||||
|
match stream.next().await {
|
||||||
|
Some(Ok(AsyncMessage::Notification(n))) => {
|
||||||
|
debug!("Handling Notification, {:?}", n);
|
||||||
if let Some(v) = listeners.get(n.channel()) {
|
if let Some(v) = listeners.get(n.channel()) {
|
||||||
for l in v {
|
for l in v {
|
||||||
l.execute(n.payload());
|
l.execute(n.payload());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Some(Ok(AsyncMessage::Notice(e))) => {
|
||||||
|
debug!("Handling Notice, {:?}", e);
|
||||||
|
}
|
||||||
|
Some(Ok(_)) => {
|
||||||
|
debug!("Handling rest");
|
||||||
|
}
|
||||||
|
Some(Err(e)) => {
|
||||||
|
debug!("Breaking loop due to error Error, {:?}", e);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
debug!("End of stream, breaking loop");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
drop(client);
|
drop(client);
|
||||||
warn!("Restarting listener task");
|
warn!("Restarting listener task");
|
||||||
|
|
Loading…
Reference in a new issue