Radish alpha
r
Radicle Job Collaborative Object
Radicle
Git (anonymous pull)
Log in to clone via SSH
chore: Add log crate with debug and warn statements
Fintan Halpenny committed 13 days ago
commit 9d951a17a5a18907e1db9ef6d32a8439f3ff5f32
parent 536de308967646831d81d2bc807f6cede24aaf99
3 files changed +27 -1
modified Cargo.lock
@@ -1507,6 +1507,7 @@ dependencies = [
 "chrono",
 "clap",
 "indexmap",
+
 "log",
 "nonempty 0.11.0",
 "once_cell",
 "qcheck",
modified Cargo.toml
@@ -15,6 +15,7 @@ rust-version = "1.86.0"
chrono = { version = "0.4.42", default-features = false }
clap = { version = "4.5.41", features = ["derive", "wrap_help"] }
indexmap = { version = "2.7.1", features = ["serde"] }
+
log = "0.4"
nonempty = "0.11.0"
once_cell = "1.20.3"
qcheck = "1.0.0"
modified src/lib.rs
@@ -56,6 +56,7 @@ use std::ops::{Deref, DerefMut};
use std::str::FromStr;

use indexmap::IndexMap;
+
use log::{debug, warn};
use once_cell::sync::Lazy;
use radicle::cob;
use radicle::cob::store::{access, Cob};
@@ -370,8 +371,10 @@ impl Job {
    fn insert(&mut self, node: NodeId, uuid: Uuid, run: Run) -> bool {
        let runs = self.runs.entry(node).or_default();
        if runs.contains_key(&uuid) {
+
            warn!("Run {uuid} already exists for node {node}, skipping");
            false
        } else {
+
            debug!("Inserting run {uuid} for node {node}");
            runs.insert(uuid, run);
            true
        }
@@ -385,13 +388,18 @@ impl Job {
        timestamp: cob::Timestamp,
    ) -> bool {
        let Some(runs) = self.runs.get_mut(&node) else {
+
            warn!("Cannot finish run {uuid}: node {node} has no runs");
            return false;
        };
        let mut updated = false;
        runs.0.entry(uuid).and_modify(|run| {
+
            debug!("Finishing run {uuid} for node {node} with {reason:?}");
            updated = true;
            *run = run.clone().finish(reason, timestamp);
        });
+
        if !updated {
+
            warn!("Cannot finish run {uuid}: not found for node {node}");
+
        }
        updated
    }

@@ -399,7 +407,9 @@ impl Job {
        match action {
            // Cannot request for another `oid`, so we ignore any superfluous
            // request actions
-
            Action::Request { .. } => {}
+
            Action::Request { .. } => {
+
                debug!("Ignoring redundant Request action from {node}");
+
            }
            Action::Run { uuid, log } => {
                self.insert(node, uuid, Run::new(log, timestamp));
            }
@@ -425,9 +435,15 @@ impl store::Cob for Job {
        let Some(Action::Request { oid }) = actions.next() else {
            return Err(error::Build::Initial);
        };
+
        debug!(
+
            "Initializing job from root: oid={oid}, author={}",
+
            op.author
+
        );
        repo.commit(oid)
            .map_err(|err| error::Build::MissingCommit { oid, err })?;
        let mut runs = Self::new(oid);
+
        let actions: Vec<_> = actions.collect();
+
        debug!("Processing {} additional actions from root", actions.len());
        for action in actions {
            runs.action(op.author, action, op.timestamp);
        }
@@ -440,6 +456,11 @@ impl store::Cob for Job {
        _concurrent: I,
        _repo: &R,
    ) -> Result<(), Self::Error> {
+
        debug!(
+
            "Applying op from {} with {} actions",
+
            op.author,
+
            op.actions.len()
+
        );
        for action in op.actions {
            self.action(op.author, action, op.timestamp);
        }
@@ -681,6 +702,7 @@ where
{
    /// Get a [`JobMut`], given its [`JobId`] identifier.
    pub fn get_mut<'g>(&'g mut self, id: &JobId) -> Result<JobMut<'a, 'g, R, S>, store::Error> {
+
        debug!("Loading mutable job {id}");
        let job = self
            .raw
            .get(id.as_object_id())?
@@ -695,6 +717,7 @@ where

    /// Create a new [`Job`] in the repository.
    pub fn create<'g>(&'g mut self, oid: Oid) -> Result<JobMut<'a, 'g, R, S>, store::Error> {
+
        debug!("Creating job for commit {oid}");
        let (id, job) = store::Transaction::initial(
            "Request job",
            &mut self.raw,
@@ -703,6 +726,7 @@ where
                Ok(())
            },
        )?;
+
        debug!("Created job {}", JobId::from(id));

        Ok(JobMut {
            id: id.into(),