Make RunInProgress fields private
This commit is contained in:
parent
b7c0443005
commit
0196709a64
2 changed files with 30 additions and 22 deletions
|
|
@ -7,7 +7,7 @@ use tokio::sync::Notify;
|
|||
use tracing::error;
|
||||
|
||||
use crate::{
|
||||
shared::{BenchMethod, FinishedRun, Measurement, Run, Source},
|
||||
shared::{BenchMethod, FinishedRun, Measurement, Run, Source, UnfinishedRun},
|
||||
somehow,
|
||||
};
|
||||
|
||||
|
|
@ -16,13 +16,14 @@ struct Finished {
|
|||
measurements: HashMap<String, Measurement>,
|
||||
}
|
||||
|
||||
// TODO Make fields private
|
||||
const SCROLLBACK: usize = 50;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct RunInProgress {
|
||||
pub server_name: String,
|
||||
pub run: Run,
|
||||
pub output: Arc<Mutex<Vec<(Source, String)>>>,
|
||||
pub abort: Arc<Notify>,
|
||||
server_name: String,
|
||||
run: Run,
|
||||
output: Arc<Mutex<Vec<(Source, String)>>>,
|
||||
abort: Arc<Notify>,
|
||||
}
|
||||
|
||||
impl RunInProgress {
|
||||
|
|
@ -35,6 +36,25 @@ impl RunInProgress {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn is_for_server(&self, name: &str) -> bool {
|
||||
self.server_name == name
|
||||
}
|
||||
|
||||
pub fn as_unfinished_run(&self) -> UnfinishedRun {
|
||||
let run = self.run.clone();
|
||||
let last_output = self
|
||||
.output
|
||||
.lock()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.rev()
|
||||
.take(SCROLLBACK)
|
||||
.rev()
|
||||
.cloned()
|
||||
.collect();
|
||||
UnfinishedRun { run, last_output }
|
||||
}
|
||||
|
||||
pub fn log_stdout(&self, line: String) {
|
||||
self.output.lock().unwrap().push((Source::Stdout, line));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,15 +7,13 @@ use tracing::{debug, warn};
|
|||
|
||||
use crate::{
|
||||
config::{Config, WorkerServerConfig},
|
||||
shared::{FinishedRun, ServerResponse, UnfinishedRun, WorkerRequest, WorkerStatus},
|
||||
shared::{FinishedRun, ServerResponse, WorkerRequest, WorkerStatus},
|
||||
somehow,
|
||||
worker::tree,
|
||||
};
|
||||
|
||||
use super::run::RunInProgress;
|
||||
|
||||
const SCROLLBACK: usize = 50;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Server {
|
||||
pub name: String,
|
||||
|
|
@ -51,19 +49,9 @@ impl Server {
|
|||
let url = format!("{}api/worker/status", self.server_config.url);
|
||||
|
||||
let status = match &*self.current_run.lock().unwrap() {
|
||||
Some(run) if run.server_name == self.name => WorkerStatus::Working(UnfinishedRun {
|
||||
run: run.run.clone(),
|
||||
last_output: run
|
||||
.output
|
||||
.lock()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.rev()
|
||||
.take(SCROLLBACK)
|
||||
.rev()
|
||||
.cloned()
|
||||
.collect(),
|
||||
}),
|
||||
Some(run) if run.is_for_server(&self.name) => {
|
||||
WorkerStatus::Working(run.as_unfinished_run())
|
||||
}
|
||||
Some(_) => WorkerStatus::Busy,
|
||||
None => WorkerStatus::Idle,
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue