Radish alpha
r
Radicle CI broker
Radicle
Git (anonymous pull)
Log in to clone via SSH
refactor: make KnownJobCobs into an enum
Lars Wirzenius committed 9 days ago
commit fd7d8a91af7ef5abb760f3a6cd677da985ad30b2
parent 7739164263509eae4cc6dfb983b358a2e92046b3
1 file changed +42 -8
modified src/cob.rs
@@ -29,13 +29,47 @@ use crate::{ergo::Oid, logger, msg::RunId};
/// Lookup cache for job COBs.
///
/// This assumes job COBs are not removed from the node.
-
pub struct KnownJobCobs {
+
pub enum KnownJobCobs {
+
    Updater(JobUpdater),
+
}
+

+
impl KnownJobCobs {
+
    /// Create a new [`KnownJobCobs`] that updates job COBs.
+
    pub fn new() -> Result<Self, JobError> {
+
        Ok(Self::Updater(JobUpdater::new()?))
+
    }
+

+
    /// Look up job COB for a specific commit.
+
    pub fn create_job(&mut self, repo_id: RepoId, oid: Oid) -> Option<JobId> {
+
        match self {
+
            Self::Updater(x) => x.create_job(repo_id, oid),
+
        }
+
    }
+

+
    /// Create a new run for an existing job. The run id should be the one
+
    /// assigned by the CI broker, not the one by the adapter. The log URL
+
    /// has to be the from the adapter.
+
    pub fn create_run(
+
        &mut self,
+
        repo_id: RepoId,
+
        oid: Oid,
+
        run_id: RunId,
+
        url: &Url,
+
        announce: bool,
+
    ) {
+
        match self {
+
            Self::Updater(x) => x.create_run(repo_id, oid, run_id, url, announce),
+
        }
+
    }
+
}
+

+
pub struct JobUpdater {
    profile: Profile,
    known: HashMap<(RepoId, Oid), JobId>,
}

-
impl KnownJobCobs {
-
    /// Create a new [`KnownJobCobs`].
+
impl JobUpdater {
+
    /// create a new [`knownjobcobs`].
    pub fn new() -> Result<Self, JobError> {
        let profile = Profile::load().map_err(JobError::profile)?;
        Ok(Self {
@@ -44,7 +78,7 @@ impl KnownJobCobs {
        })
    }

-
    /// Look up job COB for a specific commit.
+
    /// look up job cob for a specific commit.
    pub fn create_job(&mut self, repo_id: RepoId, oid: Oid) -> Option<JobId> {
        let key = (repo_id, oid);
        if let Some(job_id) = self.known.get(&key) {
@@ -71,7 +105,7 @@ impl KnownJobCobs {
            }
            Err(err) => {
                logger::job_failure(
-
                    "failed to find job COB for Git object",
+
                    "failed to find job cob for git object",
                    &repo_id,
                    &oid,
                    Some(&err),
@@ -85,8 +119,8 @@ impl KnownJobCobs {
        }
    }

-
    /// Create a new run for an existing job. The run id should be the one
-
    /// assigned by the CI broker, not the one by the adapter. The log URL
+
    /// create a new run for an existing job. the run id should be the one
+
    /// assigned by the ci broker, not the one by the adapter. the log url
    /// has to be the from the adapter.
    pub fn create_run(
        &mut self,
@@ -100,7 +134,7 @@ impl KnownJobCobs {
            && let Err(err) = self.fallible_create_run(job_id, repo_id, run_id, url, announce)
        {
            logger::job_failure(
-
                "failed to add a run to a job COB",
+
                "failed to add a run to a job cob",
                &repo_id,
                &oid,
                Some(&err),