Overhaul runner protocol

The JSON should now be nicer to work with.
This commit is contained in:
Joscha 2023-08-11 00:24:00 +02:00
parent b16b3a668e
commit 7911a67906
4 changed files with 42 additions and 25 deletions

View file

@ -55,7 +55,7 @@ impl Runners {
self.runners
.iter()
.filter_map(|(name, info)| match &info.status {
RunnerStatus::Working { hash: h, since, .. } if h == hash => Some((name, *since)),
RunnerStatus::Working(run) if run.hash == hash => Some((name, run.start)),
_ => None,
})
.max_by_key(|(_, since)| *since)
@ -64,8 +64,8 @@ impl Runners {
pub fn should_abort_work(&self, name: &str) -> bool {
let Some(info) = self.runners.get(name) else { return false; };
let RunnerStatus::Working { hash, .. } = &info.status else { return false; };
let Some(oldest) = self.oldest_working_on(hash) else { return false; };
let RunnerStatus::Working ( run) = &info.status else { return false; };
let Some(oldest) = self.oldest_working_on(&run.hash) else { return false; };
name != oldest
}
@ -74,7 +74,7 @@ impl Runners {
.runners
.values()
.filter_map(|info| match &info.status {
RunnerStatus::Working { hash, .. } => Some(hash),
RunnerStatus::Working(run) => Some(&run.hash),
_ => None,
})
.collect::<HashSet<_>>();

View file

@ -67,7 +67,7 @@ async fn post_status(
// Find new work
let work = if let Some(hash) = work {
let bench = match bench_repo {
Some(bench_repo) => BenchMethod::BenchRepo {
Some(bench_repo) => BenchMethod::Repo {
hash: bench_repo.0.to_thread_local().head_id()?.to_string(),
},
None => BenchMethod::Internal,

View file

@ -64,12 +64,12 @@ async fn get_runners(
let status = match &info.status {
RunnerStatus::Idle => Status::Idle,
RunnerStatus::Busy => Status::Busy,
RunnerStatus::Working { id, hash, .. } => {
RunnerStatus::Working(run) => {
let message =
sqlx::query_scalar!("SELECT message FROM commits WHERE hash = ?", hash)
sqlx::query_scalar!("SELECT message FROM commits WHERE hash = ?", run.hash)
.fetch_one(db)
.await?;
Status::Working(RunLink::new(base, id.clone(), hash, &message))
Status::Working(RunLink::new(base, run.id.clone(), &run.hash, &message))
}
};
@ -89,9 +89,9 @@ async fn get_queue(
// Group runners by commit hash
let mut runners_by_commit: HashMap<String, Vec<RunnerLink>> = HashMap::new();
for (name, info) in runners {
if let RunnerStatus::Working { hash, .. } = &info.status {
if let RunnerStatus::Working(run) = &info.status {
runners_by_commit
.entry(hash.clone())
.entry(run.hash.clone())
.or_default()
.push(RunnerLink::new(base, name.clone()));
}