Overhaul runner protocol
The JSON should now be nicer to work with.
This commit is contained in:
parent
b16b3a668e
commit
7911a67906
4 changed files with 42 additions and 25 deletions
|
|
@ -6,6 +6,10 @@ use serde::{Deserialize, Serialize};
|
|||
use serde_repr::{Deserialize_repr, Serialize_repr};
|
||||
use time::OffsetDateTime;
|
||||
|
||||
fn is_false(b: &bool) -> bool {
|
||||
!b
|
||||
}
|
||||
|
||||
#[derive(Clone, Serialize_repr, Deserialize_repr)]
|
||||
#[repr(i8)]
|
||||
pub enum Direction {
|
||||
|
|
@ -17,27 +21,42 @@ pub enum Direction {
|
|||
#[derive(Clone, Serialize, Deserialize)]
|
||||
pub struct Measurement {
|
||||
pub value: f64,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub stddev: Option<f64>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub unit: Option<String>,
|
||||
pub direction: Option<i8>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub direction: Option<Direction>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Serialize_repr, Deserialize_repr)]
|
||||
#[repr(u8)]
|
||||
pub enum Source {
|
||||
// Stdin would be fd 0
|
||||
Stdout = 1,
|
||||
Stderr = 2,
|
||||
}
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
#[serde(tag = "type")]
|
||||
pub enum Line {
|
||||
Stdout(String),
|
||||
Stderr(String),
|
||||
pub struct UnfinishedRun {
|
||||
pub id: String,
|
||||
pub hash: String,
|
||||
pub start: OffsetDateTime,
|
||||
#[serde(default)]
|
||||
pub last_output: Vec<(Source, String)>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
pub struct FinishedRun {
|
||||
pub id: String,
|
||||
pub hash: String,
|
||||
pub start: OffsetDateTime,
|
||||
pub end: OffsetDateTime,
|
||||
pub output: Vec<Line>,
|
||||
#[serde(default)]
|
||||
pub exit_code: i32,
|
||||
pub measurements: HashMap<String, Measurement>,
|
||||
#[serde(default)]
|
||||
pub output: Vec<(Source, String)>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
|
|
@ -49,12 +68,7 @@ pub enum RunnerStatus {
|
|||
/// The runner is performing work for another server.
|
||||
Busy,
|
||||
/// The runner is performing work for the current server.
|
||||
Working {
|
||||
id: String,
|
||||
hash: String,
|
||||
since: OffsetDateTime,
|
||||
last_lines: Vec<Line>,
|
||||
},
|
||||
Working(UnfinishedRun),
|
||||
}
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
|
|
@ -74,10 +88,11 @@ pub struct RunnerRequest {
|
|||
///
|
||||
/// If the server has a commit available, it should respond with a non-null
|
||||
/// [`Response::work`].
|
||||
#[serde(default)]
|
||||
#[serde(default, skip_serializing_if = "is_false")]
|
||||
pub request_work: bool,
|
||||
|
||||
/// The runner has finished a run and wants to submit the results.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub submit_work: Option<FinishedRun>,
|
||||
}
|
||||
|
||||
|
|
@ -88,7 +103,7 @@ pub enum BenchMethod {
|
|||
/// Use internal (deterministic) benchmarking code.
|
||||
Internal,
|
||||
/// Use a commit from a bench repo.
|
||||
BenchRepo { hash: String },
|
||||
Repo { hash: String },
|
||||
}
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
|
|
@ -107,6 +122,7 @@ pub struct ServerResponse {
|
|||
/// the next update request sent by the runner, the server will consider the
|
||||
/// runner as preparing to work on the commit, and will not give out the
|
||||
/// same commit to other runners.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub work: Option<Work>,
|
||||
|
||||
/// The runner should abort the current run.
|
||||
|
|
@ -114,5 +130,6 @@ pub struct ServerResponse {
|
|||
/// The server may send this because it detected the runner is benchmarking
|
||||
/// the same commit as another runner and has broken the tie in favor of the
|
||||
/// other runner. The runner may continue the run despite this flag.
|
||||
#[serde(default, skip_serializing_if = "is_false")]
|
||||
pub abort_work: bool,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue