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.whence().oid(),
|
||||||
run.broker_run_id().clone(),
|
run.broker_run_id().clone(),
|
||||||
&url,
|
&url,
|
||||||
|
false,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,10 @@ pub struct CobCmd {
|
|||||||
|
|
||||||
/// Create this many runs in job COB.
|
/// Create this many runs in job COB.
|
||||||
n: usize,
|
n: usize,
|
||||||
|
|
||||||
|
/// Announce changes?
|
||||||
|
#[clap(long)]
|
||||||
|
announce: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Leaf for CobCmd {
|
impl Leaf for CobCmd {
|
||||||
@@ -30,7 +34,7 @@ impl Leaf for CobCmd {
|
|||||||
for i in 0..self.n {
|
for i in 0..self.n {
|
||||||
println!("{i}");
|
println!("{i}");
|
||||||
let mut known = known.lock().unwrap();
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
+40
-30
@@ -66,7 +66,7 @@ impl KnownJobCobs {
|
|||||||
match job_for_commit(&jobs, oid) {
|
match job_for_commit(&jobs, oid) {
|
||||||
Err(JobError::NoJob(_)) => {
|
Err(JobError::NoJob(_)) => {
|
||||||
let job = jobs.create(oid, &signer).map_err(JobError::CreateJob)?;
|
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());
|
logger::job_create(&repo_id, &oid, job.id());
|
||||||
Ok(*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
|
/// 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
|
/// assigned by the CI broker, not the one by the adapter. The log URL
|
||||||
/// has to be the from the adapter.
|
/// 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 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(
|
logger::job_failure(
|
||||||
"failed to add a run to a job COB",
|
"failed to add a run to a job COB",
|
||||||
&repo_id,
|
&repo_id,
|
||||||
@@ -108,6 +115,7 @@ impl KnownJobCobs {
|
|||||||
repo_id: RepoId,
|
repo_id: RepoId,
|
||||||
run_id: RunId,
|
run_id: RunId,
|
||||||
url: &Url,
|
url: &Url,
|
||||||
|
a: bool,
|
||||||
) -> Result<(), JobError> {
|
) -> Result<(), JobError> {
|
||||||
let uuid = Uuid::from_str(run_id.as_str()).map_err(JobError::Uuid)?;
|
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)?;
|
let mut job = jobs.get_mut(&job_id).map_err(JobError::GetJobMut)?;
|
||||||
job.run(uuid, url.clone(), &signer)
|
job.run(uuid, url.clone(), &signer)
|
||||||
.map_err(JobError::AddRun)?;
|
.map_err(JobError::AddRun)?;
|
||||||
announce(&self.profile, repo_id)?;
|
|
||||||
|
announce(&self.profile, repo_id, a)?;
|
||||||
|
|
||||||
logger::job_run_create(job_id, uuid);
|
logger::job_run_create(job_id, uuid);
|
||||||
Ok(())
|
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)?;
|
let mut job = jobs.get_mut(&job_id).map_err(JobError::GetJobMut)?;
|
||||||
job.finish(uuid, reason, &signer)
|
job.finish(uuid, reason, &signer)
|
||||||
.map_err(JobError::Finish)?;
|
.map_err(JobError::Finish)?;
|
||||||
announce(&profile, repo_id)?;
|
announce(&profile, repo_id, true)?;
|
||||||
|
|
||||||
logger::job_run_finished(job_id, uuid, reason);
|
logger::job_run_finished(job_id, uuid, reason);
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -189,34 +198,35 @@ fn job_for_commit<'a>(jobs: &Jobs<'a, Repository>, wanted: Oid) -> Result<JobId,
|
|||||||
Err(JobError::NoJob(wanted))
|
Err(JobError::NoJob(wanted))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn announce(profile: &Profile, repo_id: RepoId) -> Result<(), JobError> {
|
fn announce(profile: &Profile, repo_id: RepoId, announce: bool) -> Result<(), JobError> {
|
||||||
const TIMEOUT: Duration = Duration::from_millis(5000);
|
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(
|
let (synced, unsynced) = node.seeds(repo_id).map_err(JobError::Seeds)?.iter().fold(
|
||||||
(BTreeSet::new(), BTreeSet::new()),
|
(BTreeSet::new(), BTreeSet::new()),
|
||||||
|(mut synced, mut unsynced), seed| {
|
|(mut synced, mut unsynced), seed| {
|
||||||
if seed.is_synced() {
|
if seed.is_synced() {
|
||||||
synced.insert(seed.nid);
|
synced.insert(seed.nid);
|
||||||
} else {
|
} else {
|
||||||
unsynced.insert(seed.nid);
|
unsynced.insert(seed.nid);
|
||||||
}
|
}
|
||||||
(synced, unsynced)
|
(synced, unsynced)
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
let announcer = Announcer::new(AnnouncerConfig::public(
|
let announcer = Announcer::new(AnnouncerConfig::public(
|
||||||
*profile.id(),
|
*profile.id(),
|
||||||
ReplicationFactor::MustReach(1),
|
ReplicationFactor::MustReach(1),
|
||||||
BTreeSet::new(),
|
BTreeSet::new(),
|
||||||
synced,
|
synced,
|
||||||
unsynced,
|
unsynced,
|
||||||
))
|
))
|
||||||
.map_err(|_| JobError::Announcer)?;
|
.map_err(|_| JobError::Announcer)?;
|
||||||
|
node.announce(repo_id, TIMEOUT, announcer, |_, _| ())
|
||||||
node.announce(repo_id, TIMEOUT, announcer, |_, _| ())
|
.map_err(JobError::Announce)?;
|
||||||
.map_err(JobError::Announce)?;
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user