fix: log fewer error messages from notifications subscription
This commit is contained in:
parent
816efb87a8
commit
9974b2f99f
1 changed files with 13 additions and 8 deletions
|
|
@ -8,7 +8,7 @@ use std::{
|
||||||
os::unix::io::{FromRawFd, RawFd},
|
os::unix::io::{FromRawFd, RawFd},
|
||||||
};
|
};
|
||||||
|
|
||||||
use tracing::{error, info};
|
use tracing::{error, trace};
|
||||||
use zbus::{
|
use zbus::{
|
||||||
dbus_proxy,
|
dbus_proxy,
|
||||||
export::futures_util::{SinkExt, StreamExt},
|
export::futures_util::{SinkExt, StreamExt},
|
||||||
|
|
@ -18,7 +18,7 @@ use zbus::{
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum State {
|
pub enum State {
|
||||||
Ready,
|
Ready,
|
||||||
WaitingForNotificationEvent(NotificationsAppletProxy<'static>),
|
WaitingForNotificationEvent(NotificationsAppletProxy<'static>, u8),
|
||||||
Finished,
|
Finished,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -35,15 +35,15 @@ pub fn notifications() -> Subscription<Notification> {
|
||||||
match &mut state {
|
match &mut state {
|
||||||
State::Ready => {
|
State::Ready => {
|
||||||
state = match get_proxy().await {
|
state = match get_proxy().await {
|
||||||
Ok(p) => State::WaitingForNotificationEvent(p),
|
Ok(p) => State::WaitingForNotificationEvent(p, 0),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
error!("Failed to connect to notifications daemon {}", err);
|
error!("Failed to connect to notifications daemon {}", err);
|
||||||
State::Finished
|
State::Finished
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
State::WaitingForNotificationEvent(proxy) => {
|
State::WaitingForNotificationEvent(proxy, mut fail_count) => {
|
||||||
info!("Waiting for notification events...");
|
trace!("Waiting for notification events...");
|
||||||
let mut signal = match proxy.receive_notify().await {
|
let mut signal = match proxy.receive_notify().await {
|
||||||
Ok(s) => s,
|
Ok(s) => s,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
|
@ -51,13 +51,18 @@ pub fn notifications() -> Subscription<Notification> {
|
||||||
"failed to get a stream of signals for notifications. {}",
|
"failed to get a stream of signals for notifications. {}",
|
||||||
err
|
err
|
||||||
);
|
);
|
||||||
|
fail_count = fail_count.saturating_add(1);
|
||||||
|
if fail_count > 5 {
|
||||||
|
error!("Failed to receive notification events");
|
||||||
|
state = State::Finished;
|
||||||
|
} else {
|
||||||
|
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
|
||||||
|
};
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
while let Some(msg) = signal.next().await {
|
while let Some(msg) = signal.next().await {
|
||||||
info!("Notification event");
|
|
||||||
let Some(args) = msg.args().into_iter().next() else {
|
let Some(args) = msg.args().into_iter().next() else {
|
||||||
error!("Failed to get arguments from notification signal.");
|
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
let notification = Notification::new(
|
let notification = Notification::new(
|
||||||
|
|
@ -110,7 +115,7 @@ async fn get_proxy() -> anyhow::Result<NotificationsAppletProxy<'static>> {
|
||||||
stream.set_nonblocking(true)?;
|
stream.set_nonblocking(true)?;
|
||||||
let stream = tokio::net::UnixStream::from_std(stream)?;
|
let stream = tokio::net::UnixStream::from_std(stream)?;
|
||||||
let conn = ConnectionBuilder::socket(stream).p2p().build().await?;
|
let conn = ConnectionBuilder::socket(stream).p2p().build().await?;
|
||||||
info!("Applet connection created");
|
trace!("Applet connection created");
|
||||||
let proxy = NotificationsAppletProxy::new(&conn).await?;
|
let proxy = NotificationsAppletProxy::new(&conn).await?;
|
||||||
|
|
||||||
Ok(proxy)
|
Ok(proxy)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue