Use RFC 3339 dates in worker endpoint
This commit is contained in:
parent
dd073b4c0d
commit
3de35e3ac8
4 changed files with 42 additions and 11 deletions
|
|
@ -40,7 +40,11 @@ async fn save_work(
|
||||||
let mut tx = db.begin().await?;
|
let mut tx = db.begin().await?;
|
||||||
let conn = tx.acquire().await?;
|
let conn = tx.acquire().await?;
|
||||||
|
|
||||||
let end = finished.end.unwrap_or_else(OffsetDateTime::now_utc);
|
let end = finished
|
||||||
|
.end
|
||||||
|
.map(|t| t.0)
|
||||||
|
.unwrap_or_else(OffsetDateTime::now_utc);
|
||||||
|
|
||||||
let bench_method = match finished.run.bench_method {
|
let bench_method = match finished.run.bench_method {
|
||||||
BenchMethod::Internal => "internal".to_string(),
|
BenchMethod::Internal => "internal".to_string(),
|
||||||
BenchMethod::Repo { hash } => format!("bench repo, hash {hash}"),
|
BenchMethod::Repo { hash } => format!("bench repo, hash {hash}"),
|
||||||
|
|
@ -65,7 +69,7 @@ async fn save_work(
|
||||||
bench_method,
|
bench_method,
|
||||||
worker_name,
|
worker_name,
|
||||||
worker_info,
|
worker_info,
|
||||||
finished.run.start,
|
finished.run.start.0,
|
||||||
end,
|
end,
|
||||||
finished.exit_code,
|
finished.exit_code,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ async fn status(status: &WorkerStatus, db: &SqlitePool, base: &Base) -> somehow:
|
||||||
&unfinished.run.hash,
|
&unfinished.run.hash,
|
||||||
&message,
|
&message,
|
||||||
),
|
),
|
||||||
since: util::format_time(unfinished.run.start),
|
since: util::format_time(unfinished.run.start.0),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ use time::OffsetDateTime;
|
||||||
use crate::{
|
use crate::{
|
||||||
config::Config,
|
config::Config,
|
||||||
id,
|
id,
|
||||||
shared::{BenchMethod, Run, UnfinishedRun, WorkerStatus},
|
shared::{BenchMethod, Rfc3339Time, Run, UnfinishedRun, WorkerStatus},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
|
@ -78,7 +78,7 @@ impl Workers {
|
||||||
id,
|
id,
|
||||||
hash,
|
hash,
|
||||||
bench_method,
|
bench_method,
|
||||||
start: OffsetDateTime::now_utc(),
|
start: Rfc3339Time(OffsetDateTime::now_utc()),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Reserve work so other workers don't choose it
|
// Reserve work so other workers don't choose it
|
||||||
|
|
@ -112,7 +112,7 @@ impl Workers {
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
.max_by_key(|(_, start)| *start)
|
.max_by_key(|(_, start)| start.0)
|
||||||
.map(|(name, _)| name as &str);
|
.map(|(name, _)| name as &str);
|
||||||
if oldest_working_on_commit != Some(name) {
|
if oldest_working_on_commit != Some(name) {
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -2,14 +2,38 @@
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{de, Deserialize, Serialize};
|
||||||
use serde_repr::{Deserialize_repr, Serialize_repr};
|
use serde_repr::{Deserialize_repr, Serialize_repr};
|
||||||
use time::OffsetDateTime;
|
use time::{format_description::well_known::Rfc3339, OffsetDateTime};
|
||||||
|
|
||||||
fn is_false(b: &bool) -> bool {
|
fn is_false(b: &bool) -> bool {
|
||||||
!b
|
!b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy)]
|
||||||
|
pub struct Rfc3339Time(pub OffsetDateTime);
|
||||||
|
|
||||||
|
impl serde::Serialize for Rfc3339Time {
|
||||||
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
|
where
|
||||||
|
S: serde::Serializer,
|
||||||
|
{
|
||||||
|
self.0.format(&Rfc3339).unwrap().serialize(serializer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'de> serde::Deserialize<'de> for Rfc3339Time {
|
||||||
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
|
where
|
||||||
|
D: serde::Deserializer<'de>,
|
||||||
|
{
|
||||||
|
let input: &str = serde::Deserialize::deserialize(deserializer)?;
|
||||||
|
OffsetDateTime::parse(input, &Rfc3339)
|
||||||
|
.map_err(de::Error::custom)
|
||||||
|
.map(Self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Serialize_repr, Deserialize_repr, sqlx::Type)]
|
#[derive(Clone, Serialize_repr, Deserialize_repr, sqlx::Type)]
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
pub enum Source {
|
pub enum Source {
|
||||||
|
|
@ -29,10 +53,13 @@ pub enum Direction {
|
||||||
#[derive(Clone, Serialize, Deserialize)]
|
#[derive(Clone, Serialize, Deserialize)]
|
||||||
pub struct Measurement {
|
pub struct Measurement {
|
||||||
pub value: f64,
|
pub value: f64,
|
||||||
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub stddev: Option<f64>,
|
pub stddev: Option<f64>,
|
||||||
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub unit: Option<String>,
|
pub unit: Option<String>,
|
||||||
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub direction: Option<Direction>,
|
pub direction: Option<Direction>,
|
||||||
}
|
}
|
||||||
|
|
@ -50,13 +77,14 @@ pub struct Run {
|
||||||
pub id: String,
|
pub id: String,
|
||||||
pub hash: String,
|
pub hash: String,
|
||||||
pub bench_method: BenchMethod,
|
pub bench_method: BenchMethod,
|
||||||
pub start: OffsetDateTime,
|
pub start: Rfc3339Time,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Serialize, Deserialize)]
|
#[derive(Clone, Serialize, Deserialize)]
|
||||||
pub struct UnfinishedRun {
|
pub struct UnfinishedRun {
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
pub run: Run,
|
pub run: Run,
|
||||||
|
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub last_output: Vec<(Source, String)>,
|
pub last_output: Vec<(Source, String)>,
|
||||||
}
|
}
|
||||||
|
|
@ -70,8 +98,7 @@ pub struct FinishedRun {
|
||||||
///
|
///
|
||||||
/// Should not be used in normal operation, but can be used when importing
|
/// Should not be used in normal operation, but can be used when importing
|
||||||
/// completed runs from other sources.
|
/// completed runs from other sources.
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
pub end: Option<Rfc3339Time>,
|
||||||
pub end: Option<OffsetDateTime>,
|
|
||||||
|
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub exit_code: i32,
|
pub exit_code: i32,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue