mirror of
https://seed.radicle.dev/rad:zwTxygwuz5LDGBq255RA2CbNGrz8.git
synced 2026-10-18 19:30:29 +08:00
feat: make announcing option for "cibool cob"
This commit is contained in:
@@ -292,6 +292,7 @@ impl Adapter {
|
||||
run.whence().oid(),
|
||||
run.broker_run_id().clone(),
|
||||
&url,
|
||||
false,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,10 @@ pub struct CobCmd {
|
||||
|
||||
/// Create this many runs in job COB.
|
||||
n: usize,
|
||||
|
||||
/// Announce changes?
|
||||
#[clap(long)]
|
||||
announce: bool,
|
||||
}
|
||||
|
||||
impl Leaf for CobCmd {
|
||||
@@ -30,7 +34,7 @@ impl Leaf for CobCmd {
|
||||
for i in 0..self.n {
|
||||
println!("{i}");
|
||||
let mut known = known.lock().unwrap();
|
||||
known.create_run(self.repo_id, self.oid, run_id.clone(), &url);
|
||||
known.create_run(self.repo_id, self.oid, run_id.clone(), &url, self.announce);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
+40
-30
@@ -66,7 +66,7 @@ impl KnownJobCobs {
|
||||
match job_for_commit(&jobs, oid) {
|
||||
Err(JobError::NoJob(_)) => {
|
||||
let job = jobs.create(oid, &signer).map_err(JobError::CreateJob)?;
|
||||
announce(&self.profile, repo_id)?;
|
||||
announce(&self.profile, repo_id, false)?;
|
||||
logger::job_create(&repo_id, &oid, job.id());
|
||||
Ok(*job.id())
|
||||
}
|
||||
@@ -89,9 +89,16 @@ 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
|
||||
/// has to be the from the adapter.
|
||||
pub fn create_run(&mut self, repo_id: RepoId, oid: Oid, run_id: RunId, url: &Url) {
|
||||
pub fn create_run(
|
||||
&mut self,
|
||||
repo_id: RepoId,
|
||||
oid: Oid,
|
||||
run_id: RunId,
|
||||
url: &Url,
|
||||
announce: bool,
|
||||
) {
|
||||
if let Some(job_id) = self.create_job(repo_id, oid) {
|
||||
if let Err(err) = self.fallible_create_run(job_id, repo_id, run_id, url) {
|
||||
if 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",
|
||||
&repo_id,
|
||||
@@ -108,6 +115,7 @@ impl KnownJobCobs {
|
||||
repo_id: RepoId,
|
||||
run_id: RunId,
|
||||
url: &Url,
|
||||
a: bool,
|
||||
) -> Result<(), JobError> {
|
||||
let uuid = Uuid::from_str(run_id.as_str()).map_err(JobError::Uuid)?;
|
||||
|
||||
@@ -118,7 +126,8 @@ impl KnownJobCobs {
|
||||
let mut job = jobs.get_mut(&job_id).map_err(JobError::GetJobMut)?;
|
||||
job.run(uuid, url.clone(), &signer)
|
||||
.map_err(JobError::AddRun)?;
|
||||
announce(&self.profile, repo_id)?;
|
||||
|
||||
announce(&self.profile, repo_id, a)?;
|
||||
|
||||
logger::job_run_create(job_id, uuid);
|
||||
Ok(())
|
||||
@@ -156,7 +165,7 @@ fn finish(repo_id: RepoId, oid: Oid, run_id: RunId, reason: Reason) -> Result<()
|
||||
let mut job = jobs.get_mut(&job_id).map_err(JobError::GetJobMut)?;
|
||||
job.finish(uuid, reason, &signer)
|
||||
.map_err(JobError::Finish)?;
|
||||
announce(&profile, repo_id)?;
|
||||
announce(&profile, repo_id, true)?;
|
||||
|
||||
logger::job_run_finished(job_id, uuid, reason);
|
||||
Ok(())
|
||||
@@ -189,34 +198,35 @@ fn job_for_commit<'a>(jobs: &Jobs<'a, Repository>, wanted: Oid) -> Result<JobId,
|
||||
Err(JobError::NoJob(wanted))
|
||||
}
|
||||
|
||||
fn announce(profile: &Profile, repo_id: RepoId) -> Result<(), JobError> {
|
||||
const TIMEOUT: Duration = Duration::from_millis(5000);
|
||||
fn announce(profile: &Profile, repo_id: RepoId, announce: bool) -> Result<(), JobError> {
|
||||
if announce {
|
||||
const TIMEOUT: Duration = Duration::from_millis(5000);
|
||||
|
||||
let mut node = Node::new(profile.home.socket());
|
||||
let mut node = Node::new(profile.home.socket());
|
||||
|
||||
let (synced, unsynced) = node.seeds(repo_id).map_err(JobError::Seeds)?.iter().fold(
|
||||
(BTreeSet::new(), BTreeSet::new()),
|
||||
|(mut synced, mut unsynced), seed| {
|
||||
if seed.is_synced() {
|
||||
synced.insert(seed.nid);
|
||||
} else {
|
||||
unsynced.insert(seed.nid);
|
||||
}
|
||||
(synced, unsynced)
|
||||
},
|
||||
);
|
||||
let (synced, unsynced) = node.seeds(repo_id).map_err(JobError::Seeds)?.iter().fold(
|
||||
(BTreeSet::new(), BTreeSet::new()),
|
||||
|(mut synced, mut unsynced), seed| {
|
||||
if seed.is_synced() {
|
||||
synced.insert(seed.nid);
|
||||
} else {
|
||||
unsynced.insert(seed.nid);
|
||||
}
|
||||
(synced, unsynced)
|
||||
},
|
||||
);
|
||||
|
||||
let announcer = Announcer::new(AnnouncerConfig::public(
|
||||
*profile.id(),
|
||||
ReplicationFactor::MustReach(1),
|
||||
BTreeSet::new(),
|
||||
synced,
|
||||
unsynced,
|
||||
))
|
||||
.map_err(|_| JobError::Announcer)?;
|
||||
|
||||
node.announce(repo_id, TIMEOUT, announcer, |_, _| ())
|
||||
.map_err(JobError::Announce)?;
|
||||
let announcer = Announcer::new(AnnouncerConfig::public(
|
||||
*profile.id(),
|
||||
ReplicationFactor::MustReach(1),
|
||||
BTreeSet::new(),
|
||||
synced,
|
||||
unsynced,
|
||||
))
|
||||
.map_err(|_| JobError::Announcer)?;
|
||||
node.announce(repo_id, TIMEOUT, announcer, |_, _| ())
|
||||
.map_err(JobError::Announce)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user