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