Start runs and coordinate with server
This commit is contained in:
parent
f79468c871
commit
b23fc6460f
6 changed files with 296 additions and 32 deletions
93
src/worker/run.rs
Normal file
93
src/worker/run.rs
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
use std::{
|
||||
collections::HashMap,
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
|
||||
use time::OffsetDateTime;
|
||||
use tokio::sync::mpsc;
|
||||
|
||||
use crate::{
|
||||
id,
|
||||
shared::{BenchMethod, FinishedRun, Measurement, Source, UnfinishedRun},
|
||||
};
|
||||
|
||||
const LIVE_SCROLLBACK: usize = 50;
|
||||
|
||||
pub enum FullRunStatus {
|
||||
Unfinished(UnfinishedRun),
|
||||
Finished(FinishedRun),
|
||||
Aborted,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum RunStatus {
|
||||
Unfinished,
|
||||
Finished {
|
||||
end: OffsetDateTime,
|
||||
exit_code: i32,
|
||||
measurements: HashMap<String, Measurement>,
|
||||
},
|
||||
Aborted,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Run {
|
||||
id: String,
|
||||
hash: String,
|
||||
start: OffsetDateTime,
|
||||
output: Vec<(Source, String)>,
|
||||
status: RunStatus,
|
||||
}
|
||||
|
||||
impl Run {
|
||||
pub fn new(hash: String) -> Self {
|
||||
Self {
|
||||
id: id::random_run_id(),
|
||||
hash,
|
||||
start: OffsetDateTime::now_utc(),
|
||||
output: vec![],
|
||||
status: RunStatus::Unfinished,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn into_full_status(self) -> FullRunStatus {
|
||||
match self.status {
|
||||
RunStatus::Unfinished => FullRunStatus::Unfinished(UnfinishedRun {
|
||||
id: self.id,
|
||||
hash: self.hash,
|
||||
start: self.start,
|
||||
last_output: self
|
||||
.output
|
||||
.into_iter()
|
||||
.rev()
|
||||
.take(LIVE_SCROLLBACK)
|
||||
.rev()
|
||||
.collect(),
|
||||
}),
|
||||
|
||||
RunStatus::Finished {
|
||||
end,
|
||||
exit_code,
|
||||
measurements,
|
||||
} => FullRunStatus::Finished(FinishedRun {
|
||||
id: self.id,
|
||||
hash: self.hash,
|
||||
start: self.start,
|
||||
end,
|
||||
exit_code,
|
||||
measurements,
|
||||
output: self.output,
|
||||
}),
|
||||
|
||||
RunStatus::Aborted => FullRunStatus::Aborted,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn run(
|
||||
run: Arc<Mutex<Run>>,
|
||||
abort_rx: mpsc::UnboundedReceiver<()>,
|
||||
bench_method: BenchMethod,
|
||||
) {
|
||||
// TODO Implement
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue