Radish alpha
r
Radicle Job Collaborative Object
Radicle
Git (anonymous pull)
Log in to clone via SSH
feat: allow a new log to be added to the finishing status
✗ CI failure Richard Levitte committed 2 months ago
commit 538c1b38169bc687adfdbfed915590529c05c4ff
parent 8799f728bc1b2e8d1824d2e06557059f8c82127d
1 failed (1 total) View logs
2 files changed +37 -15
modified src/bin/rad-job.rs
@@ -187,7 +187,7 @@ where
}

fn succeeded_job<G>(
-
    command::Succeeded { oid, run }: command::Succeeded,
+
    command::Succeeded { oid, run, url }: command::Succeeded,
    jobs: &mut Jobs<'_, Repository>,
    signer: &Device<G>,
) -> Result<(), error::Succeeded>
@@ -196,13 +196,13 @@ where
{
    let (id, job) = find_by_commit(oid, jobs)?;
    let mut job = JobMut::new(id, job, jobs);
-
    job.finish(run, Reason::Succeeded, signer)
+
    job.finish(run, Reason::Succeeded, url, signer)
        .map_err(|err| error::Succeeded::Store { id, err })?;
    Ok(())
}

fn failed_job<G>(
-
    command::Failed { oid, run }: command::Failed,
+
    command::Failed { oid, run, url }: command::Failed,
    jobs: &mut Jobs<'_, Repository>,
    signer: &Device<G>,
) -> Result<(), error::Failed>
@@ -211,7 +211,7 @@ where
{
    let (id, job) = find_by_commit(oid, jobs)?;
    let mut job = JobMut::new(id, job, jobs);
-
    job.finish(run, Reason::Failed, signer)
+
    job.finish(run, Reason::Failed, url, signer)
        .map_err(|err| error::Failed::Store { id, err })?;
    Ok(())
}
@@ -368,7 +368,7 @@ mod command {
    pub struct Run {
        /// Git commit which the run is processing.
        pub oid: Oid,
-
        /// URL to information about the run, such a a run log.
+
        /// URL to information about the run, such a live run log.
        pub url: Url,
    }

@@ -379,6 +379,8 @@ mod command {
        pub oid: Oid,
        /// Run identifier, a UUID.
        pub run: Uuid,
+
        /// URL to information about the run, such a saved run log.
+
        pub url: Option<Url>,
    }

    /// Mark a run as having finished successfully.
@@ -388,6 +390,8 @@ mod command {
        pub oid: Oid,
        /// Run identifier, a UUID.
        pub run: Uuid,
+
        /// URL to information about the run, such a saved run log.
+
        pub url: Option<Url>,
    }
}

modified src/lib.rs
@@ -275,6 +275,8 @@ pub enum Action {
        uuid: Uuid,
        /// The [`Reason`] which the node finished with.
        reason: Reason,
+
        /// The [`Url`] where the node will log any information or data.
+
        log: Option<Url>,
    },
}

@@ -381,6 +383,7 @@ impl Job {
        node: NodeId,
        uuid: Uuid,
        reason: Reason,
+
        log: Option<Url>,
        timestamp: cob::Timestamp,
    ) -> bool {
        let Some(runs) = self.runs.get_mut(&node) else {
@@ -389,7 +392,7 @@ impl Job {
        let mut updated = false;
        runs.0.entry(uuid).and_modify(|run| {
            updated = true;
-
            *run = run.clone().finish(reason, timestamp);
+
            *run = run.clone().finish(reason, log, timestamp);
        });
        updated
    }
@@ -402,8 +405,8 @@ impl Job {
            Action::Run { uuid, log } => {
                self.insert(node, uuid, Run::new(log, timestamp));
            }
-
            Action::Finished { uuid, reason } => {
-
                self.update(node, uuid, reason, timestamp);
+
            Action::Finished { uuid, reason, log } => {
+
                self.update(node, uuid, reason, log, timestamp);
            }
        }
    }
@@ -502,10 +505,10 @@ impl Run {
    }

    /// Mark the `Run` as finished.
-
    fn finish(self, reason: Reason, timestamp: cob::Timestamp) -> Self {
+
    fn finish(self, reason: Reason, log: Option<Url>, timestamp: cob::Timestamp) -> Self {
        Self {
            status: Status::Finished(reason),
-
            log: self.log,
+
            log: log.unwrap_or(self.log),
            timestamp,
        }
    }
@@ -775,12 +778,13 @@ where
        &mut self,
        uuid: Uuid,
        reason: Reason,
+
        log: Option<Url>,
        signer: &Device<G>,
    ) -> Result<EntryId, store::Error>
    where
        G: Signer<crypto::Signature>,
    {
-
        self.transaction("Finished node job", signer, |tx| tx.finish(uuid, reason))
+
        self.transaction("Finished node job", signer, |tx| tx.finish(uuid, reason, log))
    }

    /// Apply COB operations to a `JobMut`.
@@ -871,8 +875,8 @@ where
    }

    /// Mark a run as finished.
-
    fn finish(&mut self, uuid: Uuid, reason: Reason) -> Result<(), store::Error> {
-
        self.0.push(Action::Finished { uuid, reason })
+
    fn finish(&mut self, uuid: Uuid, reason: Reason, log: Option<Url>) -> Result<(), store::Error> {
+
        self.0.push(Action::Finished { uuid, reason, log })
    }
}

@@ -935,14 +939,18 @@ mod test {
        assert_eq!(run.status, Status::Started);
        assert_eq!(run.log, bob_log);

-
        job.finish(alice_uuid, Reason::Succeeded, &alice.signer)
+
        job.finish(alice_uuid, Reason::Succeeded, None, &alice.signer)
            .unwrap();

        let finished = job.finished();
        assert!(finished.contains_key(alice.signer.public_key()));
        assert!(!finished.contains_key(bob.signer.public_key()));

-
        job.finish(bob_uuid, Reason::Failed, &bob.signer).unwrap();
+
        // [TODO] replace RID, NID and COMMIT with the actual repo ID, node ID
+
        // and a real commit ID for the log itself.
+
        let bob_finish_log = Url::parse(&format!("rad:RID/NID/blob/COMMIT?path=run-log.md")).unwrap();
+

+
        job.finish(bob_uuid, Reason::Failed, Some(bob_finish_log.clone()), &bob.signer).unwrap();

        let succeeded = job.succeeded();
        assert!(succeeded.contains_key(alice.signer.public_key()));
@@ -952,6 +960,16 @@ mod test {
        assert!(failed.contains_key(bob.signer.public_key()));
        let started = job.started();
        assert!(started.is_empty());
+

+
        // Check that we still have alice's initial log
+
        let alice_runs = job.runs_of(alice.signer.public_key()).unwrap();
+
        let run = alice_runs.get(&alice_uuid).unwrap();
+
        assert_eq!(run.log, alice_log);
+

+
        // Check that we have bob's finishing log
+
        let bob_runs = job.runs_of(bob.signer.public_key()).unwrap();
+
        let run = bob_runs.get(&bob_uuid).unwrap();
+
        assert_eq!(run.log, bob_finish_log);
    }

    #[test]