feat: add a variant to KnownJobCobs that makes no updates

This commit is contained in:
Lars Wirzenius
2026-05-11 14:30:34 +03:00
parent fd7d8a91af
commit ecce2a73a5
5 changed files with 14 additions and 5 deletions
+1 -1
View File
@@ -535,7 +535,7 @@ mod test {
#[allow(clippy::unwrap_used)] #[allow(clippy::unwrap_used)]
fn known() -> Arc<Mutex<KnownJobCobs>> { fn known() -> Arc<Mutex<KnownJobCobs>> {
Arc::new(Mutex::new(KnownJobCobs::new().unwrap())) Arc::new(Mutex::new(KnownJobCobs::updater().unwrap()))
} }
#[allow(clippy::unwrap_used)] #[allow(clippy::unwrap_used)]
+1 -1
View File
@@ -29,7 +29,7 @@ impl Leaf for CobCmd {
let url = Url::parse("https://liw.fi").unwrap(); let url = Url::parse("https://liw.fi").unwrap();
let run_id = RunId::default(); let run_id = RunId::default();
let known = Arc::new(Mutex::new( let known = Arc::new(Mutex::new(
KnownJobCobs::new().map_err(CibToolError::KnownJobCobs)?, KnownJobCobs::updater().map_err(CibToolError::KnownJobCobs)?,
)); ));
for i in 0..self.n { for i in 0..self.n {
println!("{i}"); println!("{i}");
+1 -1
View File
@@ -223,7 +223,7 @@ mod test {
#[allow(clippy::unwrap_used)] #[allow(clippy::unwrap_used)]
fn known() -> Arc<Mutex<KnownJobCobs>> { fn known() -> Arc<Mutex<KnownJobCobs>> {
Arc::new(Mutex::new(KnownJobCobs::new().unwrap())) Arc::new(Mutex::new(KnownJobCobs::updater().unwrap()))
} }
#[test] #[test]
+10 -1
View File
@@ -29,19 +29,27 @@ use crate::{ergo::Oid, logger, msg::RunId};
/// Lookup cache for job COBs. /// Lookup cache for job COBs.
/// ///
/// This assumes job COBs are not removed from the node. /// This assumes job COBs are not removed from the node.
#[allow(clippy::large_enum_variant)]
pub enum KnownJobCobs { pub enum KnownJobCobs {
NoUpdates,
Updater(JobUpdater), Updater(JobUpdater),
} }
impl KnownJobCobs { impl KnownJobCobs {
/// Cre3ate q new [`KnownJobCobs`] that does NOT update job COBs.
pub fn no_updater() -> Self {
Self::NoUpdates
}
/// Create a new [`KnownJobCobs`] that updates job COBs. /// Create a new [`KnownJobCobs`] that updates job COBs.
pub fn new() -> Result<Self, JobError> { pub fn updater() -> Result<Self, JobError> {
Ok(Self::Updater(JobUpdater::new()?)) Ok(Self::Updater(JobUpdater::new()?))
} }
/// 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> { pub fn create_job(&mut self, repo_id: RepoId, oid: Oid) -> Option<JobId> {
match self { match self {
Self::NoUpdates => None,
Self::Updater(x) => x.create_job(repo_id, oid), Self::Updater(x) => x.create_job(repo_id, oid),
} }
} }
@@ -58,6 +66,7 @@ impl KnownJobCobs {
announce: bool, announce: bool,
) { ) {
match self { match self {
Self::NoUpdates => (),
Self::Updater(x) => x.create_run(repo_id, oid, run_id, url, announce), Self::Updater(x) => x.create_run(repo_id, oid, run_id, url, announce),
} }
} }
+1 -1
View File
@@ -76,7 +76,7 @@ impl QueueProcessorBuilder {
child_pid_tx, child_pid_tx,
child_pid_rx, child_pid_rx,
known_job_cobs: Arc::new(Mutex::new( known_job_cobs: Arc::new(Mutex::new(
KnownJobCobs::new().map_err(QueueError::KnownJobCobs)?, KnownJobCobs::updater().map_err(QueueError::KnownJobCobs)?,
)), )),
}) })
} }