Radish alpha
r
Radicle CI broker
Radicle
Git (anonymous pull)
Log in to clone via SSH
feat: log when a NodeSourceEvent is created
Lars Wirzenius committed 1 year ago
commit 21b14a2328be75f233f70a1eb7be35e87efb2f92
parent 92bee78f7820ff5d176ad67e0f6b85dc3a7f59d5
2 files changed +22 -3
modified src/logger.rs
@@ -13,6 +13,7 @@ use crate::{
    config::Config,
    db::{QueueId, QueuedCiEvent},
    msg::Request,
+
    node_event_source::NodeEventSource,
    run::Run,
};

@@ -70,6 +71,14 @@ pub fn end_cib_in_error() {
    );
}

+
pub fn node_event_source_created(source: &NodeEventSource) {
+
    info!(
+
        slog_scope::logger(),
+
        "created node event source";
+
        "source" => format!("{source:#?}")
+
    );
+
}
+

pub fn loaded_config(config: &Config) {
    debug!(slog_scope::logger(), "loaded configuration {config:#?}");
}
modified src/node_event_source.rs
@@ -1,6 +1,6 @@
//! Read node events from the local node.

-
use std::{path::PathBuf, time};
+
use std::{fmt, path::PathBuf, time};

use radicle::{
    node::{Event, Handle},
@@ -11,6 +11,7 @@ use crate::logger;

/// Source of events from the local Radicle node.
pub struct NodeEventSource {
+
    profile_path: PathBuf,
    events: Box<dyn Iterator<Item = Result<Event, radicle::node::Error>>>,
}

@@ -23,15 +24,18 @@ impl NodeEventSource {
            return Err(NodeEventError::NoControlSocket(socket));
        }
        let node = radicle::Node::new(socket.clone());
-
        match node.subscribe(time::Duration::MAX) {
+
        let source = match node.subscribe(time::Duration::MAX) {
            Ok(events) => Ok(Self {
+
                profile_path: profile.home.path().into(),
                events: Box::new(events.into_iter()),
            }),
            Err(err) => {
                logger::error("failed to subscribe to node events", &err);
                Err(NodeEventError::CannotSubscribe(socket.clone(), err))
            }
-
        }
+
        }?;
+
        logger::node_event_source_created(&source);
+
        Ok(source)
    }

    /// Get the next node event from an event source, without
@@ -59,6 +63,12 @@ impl NodeEventSource {
    }
}

+
impl fmt::Debug for NodeEventSource {
+
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+
        write!(f, "NodeEventSource<path={}", self.profile_path.display())
+
    }
+
}
+

/// Possible errors from accessing the local Radicle node.
#[derive(Debug, thiserror::Error)]
pub enum NodeEventError {