Radish alpha
r
rad:zwTxygwuz5LDGBq255RA2CbNGrz8
Radicle CI broker
Radicle
Git
Add job COB ID to run information
Merged liw opened 8 months ago
7 files changed +85 -28 5e32f7f3 b177b785
modified src/bin/cibtoolcmd/run.rs
@@ -1,6 +1,7 @@
use std::collections::HashSet;

use radicle_ci_broker::run::RunBuilder;
+
use radicle_job::JobId;

use super::*;

@@ -51,6 +52,10 @@ pub struct AddRun {
    /// Mark the CI run as finished and failed.
    #[clap(long, required_unless_present_any = ["triggered", "running", "success"])]
    failure: bool,
+

+
    /// Record job COB ID created for this run.
+
    #[clap(long)]
+
    job: Option<JobId>,
}

impl Leaf for AddRun {
@@ -82,6 +87,10 @@ impl Leaf for AddRun {
            run.set_adapter_info_url(url);
        }

+
        if let Some(job) = &self.job {
+
            run.set_job_id(*job);
+
        }
+

        if self.triggered {
            run.set_state(RunState::Triggered);
            run.unset_result();
modified src/broker.rs
@@ -125,7 +125,9 @@ impl Broker {
        // it. We won't do anything about a failure, as there's
        // nothing useful we can do about it, as long as we let CI
        // run, which want to do.
-
        create_job(trigger.repo(), oid);
+
        if let Some(job_id) = create_job(trigger.repo(), oid) {
+
            run.set_job_id(job_id);
+
        }

        // We run the adapter, but if that fails, we just
        // log the error. The `Run` value records the
modified src/cob.rs
@@ -28,8 +28,8 @@ use crate::{logger, msg::RunId};
/// it is not necessary to keep the job id (indeed, that is not
/// returned). Separate instances of the CI broker have no way of
/// communicating the job id.
-
pub fn create_job(repo_id: RepoId, oid: Oid) {
-
    fn fallible_create(repo_id: RepoId, oid: Oid) -> Result<(), JobError> {
+
pub fn create_job(repo_id: RepoId, oid: Oid) -> Option<JobId> {
+
    fn fallible_create(repo_id: RepoId, oid: Oid) -> Result<JobId, JobError> {
        let profile = profile()?;
        let repo = repository(&profile, repo_id)?;
        let signer = profile.signer().map_err(JobError::Signer)?;
@@ -40,7 +40,7 @@ pub fn create_job(repo_id: RepoId, oid: Oid) {
                let job = jobs.create(oid, &signer).map_err(JobError::CreateJob)?;
                announce(&profile, repo_id)?;
                logger::job_create(&repo_id, &oid, job.id());
-
                Ok(())
+
                Ok(*job.id())
            }
            Err(err) => {
                logger::job_failure(
@@ -51,19 +51,14 @@ pub fn create_job(repo_id: RepoId, oid: Oid) {
                );
                Err(err)
            }
-
            Ok(_) => {
-
                logger::job_failure(
-
                    "job COB for Git object already exists",
-
                    &repo_id,
-
                    &oid,
-
                    None,
-
                );
-
                Err(JobError::JobExists(oid))
+
            Ok(job_id) => {
+
                logger::job_reuse(&repo_id, &oid, &job_id);
+
                Ok(job_id)
            }
        }
    }

-
    fallible_create(repo_id, oid).ok();
+
    fallible_create(repo_id, oid).ok()
}

/// Create a new run for an existing job. The run id should be the one
modified src/logger.rs
@@ -868,6 +868,17 @@ pub fn job_create(repo_id: &RepoId, oid: &Oid, job_id: &JobId) {
    );
}

+
pub fn job_reuse(repo_id: &RepoId, oid: &Oid, job_id: &JobId) {
+
    debug!(
+
        msg_id = ?Id::JobCreate,
+
        kind = %Kind::StartRun,
+
        ?repo_id,
+
        ?oid,
+
        ?job_id,
+
        "created job COB",
+
    );
+
}
+

pub fn job_run_create(job_id: JobId, run_id: Uuid) {
    debug!(
        msg_id = ?Id::JobRunCreate,
modified src/pages.rs
@@ -472,19 +472,34 @@ impl PageData {
                Element::new(Tag::Span)
            };

-
            Element::new(Tag::Span).with_child(
-
                Element::new(Tag::Span)
-
                    .with_class("adapter-run-id")
-
                    .with_child(adapter_run_id)
-
                    .with_child(Element::new(Tag::Br))
-
                    .with_child(
-
                        Element::new(Tag::Span)
-
                            .with_class("broker-run-id")
-
                            .with_text(&run.broker_run_id().to_string()),
-
                    )
-
                    .with_child(Element::new(Tag::Br))
-
                    .with_text(run.timestamp()),
-
            )
+
            Element::new(Tag::Span)
+
                .with_child(
+
                    Element::new(Tag::Span)
+
                        .with_class("adapter-run-id")
+
                        .with_text("Adapter: ")
+
                        .with_child(adapter_run_id)
+
                        .with_child(Element::new(Tag::Br)),
+
                )
+
                .with_child(
+
                    Element::new(Tag::Span)
+
                        .with_class("broker-run-id")
+
                        .with_text("Broker: ")
+
                        .with_text(&run.broker_run_id().to_string()),
+
                )
+
                .with_child(Element::new(Tag::Br))
+
                .with_child(
+
                    Element::new(Tag::Span)
+
                        .with_class("timestamp")
+
                        .with_text("Started: ")
+
                        .with_text(run.timestamp()),
+
                )
+
                .with_child(Element::new(Tag::Br))
+
                .with_child(
+
                    Element::new(Tag::Span)
+
                        .with_class("job-cob-id")
+
                        .with_text("Job: ")
+
                        .with_text(&run.job_id().map(|id| id.to_string()).unwrap_or("".into())),
+
                )
        } else {
            Element::new(Tag::Span)
        }
modified src/radicle-ci.css
@@ -46,12 +46,24 @@ code.repoid, span.repoid {
    font-weight: bold;
}

-
span.broker_run_id {
+
span.broker-run-id {
    font-style: monospace;
+
    font-size: 80%;
}

-
span.adapter_run_id {
+
span.adapter-run-id {
    font-style: monospace;
+
    font-size: 80%;
+
}
+

+
span.timestamp {
+
    font-style: monospace;
+
    font-size: 80%;
+
}
+

+
span.job-cob-id {
+
    font-style: monospace;
+
    font-size: 80%;
}

span.triggered {
modified src/run.rs
@@ -4,6 +4,7 @@ use serde::{Deserialize, Serialize};

use radicle::git::Oid;
use radicle::prelude::RepoId;
+
use radicle_job::JobId;

use crate::msg::{Revision, RunId, RunResult};

@@ -59,6 +60,7 @@ impl RunBuilder {
            broker_run_id,
            adapter_run_id: None,
            adapter_info_url: None,
+
            job_id: None,
            repo_id,
            repo_name,
            timestamp,
@@ -74,6 +76,7 @@ pub struct Run {
    broker_run_id: RunId,
    adapter_run_id: Option<RunId>,
    adapter_info_url: Option<String>,
+
    job_id: Option<JobId>,
    repo_id: RepoId,
    #[serde(alias = "repo_alias")]
    repo_name: String,
@@ -84,6 +87,16 @@ pub struct Run {
}

impl Run {
+
    /// Set job COB ID.
+
    pub fn set_job_id(&mut self, job_id: JobId) {
+
        self.job_id = Some(job_id);
+
    }
+

+
    /// Job COB ID, if set.
+
    pub fn job_id(&self) -> Option<JobId> {
+
        self.job_id
+
    }
+

    /// Return the repo alias.
    pub fn repo_alias(&self) -> &str {
        &self.repo_name