refactor: make KnownJobCobs into an enum

This is in preparation of adding a do-not-update variant.
This commit is contained in:
Lars Wirzenius
2026-05-11 14:26:02 +03:00
parent 7739164263
commit fd7d8a91af
+42 -8
View File
@@ -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),