Skip to content

Commit 59689eb

Browse files
committed
Auto merge of #620 - Mark-Simulacrum:drop-humanize-dep, r=Mark-Simulacrum
Humanize to hours at most Days are typically fairly non-granular, and most of our runtimes are roughly in the 48 hour-ish window. Hours should give a much better picture of when to expect results. This also drops a dependency in favor of manually humanizing the time.
2 parents f9baf09 + 11ec3c4 commit 59689eb

File tree

6 files changed

+39
-52
lines changed

6 files changed

+39
-52
lines changed

Cargo.lock

Lines changed: 0 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ opt-level = 0
1616
base64 = "0.13.0"
1717
bytes = "0.4.9"
1818
chrono = { version = "0.4", features = ["serde"] }
19-
chrono-humanize = "0.1.1"
2019
crates-index = "0.16.2"
2120
crossbeam-utils = "0.5"
2221
crossbeam-channel = "0.5"

src/crates/lists.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ pub(crate) fn get_crates(
8888
all_crates.append(&mut GitHubList::get(db)?);
8989
all_crates.append(&mut LocalList::get(db)?);
9090

91-
for krate in all_crates.drain(..) {
91+
for krate in all_crates {
9292
let add = match krate {
9393
Crate::Registry(RegistryCrate { ref name, .. }) => demo_registry.remove(name),
9494
Crate::GitHub(ref repo) => demo_github.remove(&repo.slug()),

src/runner/graph.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,11 @@ impl TasksGraph {
155155

156156
// Try to check for the dependencies of this node
157157
// The list is collected to make the borrowchecker happy
158-
let mut neighbors = self.graph.neighbors(node).collect::<Vec<_>>();
158+
let neighbors = self.graph.neighbors(node).collect::<Vec<_>>();
159159
log::trace!("{} | {:?}: neighbors: {:?}", worker, node, neighbors);
160160

161161
let mut blocked = false;
162-
for neighbor in neighbors.drain(..) {
162+
for neighbor in neighbors {
163163
match self.walk_graph(neighbor, ex, db, worker) {
164164
WalkResult::Task(id, task) => return WalkResult::Task(id, task),
165165
WalkResult::Finished => return WalkResult::Finished,
@@ -219,12 +219,12 @@ impl TasksGraph {
219219
result: &TestResult,
220220
worker: &str,
221221
) -> Fallible<()> {
222-
let mut children = self
222+
let children = self
223223
.graph
224224
.neighbors_directed(node, Direction::Incoming)
225225
.collect::<Vec<_>>();
226226
let mut last_err = None;
227-
for child in children.drain(..) {
227+
for child in children {
228228
// Don't recursively mark a child as failed if this is not the only parent of the child
229229
let parents = self
230230
.graph

src/runner/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ pub fn run_ex<DB: WriteResults + Sync>(
157157
Ok(())
158158
})?;
159159

160-
let clean_exit = join_threads(threads.drain(..));
160+
let clean_exit = join_threads(threads.into_iter());
161161
disk_watcher.stop();
162162
let disk_watcher_clean_exit = join_threads(std::iter::once(disk_watcher_thread));
163163

src/server/routes/ui/experiments.rs

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use crate::report::ResultName;
44
use crate::server::routes::ui::{render_template, LayoutContext};
55
use crate::server::{Data, HttpError};
66
use chrono::{Duration, SecondsFormat, Utc};
7-
use chrono_humanize::{Accuracy, HumanTime, Tense};
87
use http::Response;
98
use hyper::Body;
109
use std::collections::HashMap;
@@ -134,6 +133,17 @@ struct ExperimentContext {
134133
layout: LayoutContext,
135134
}
136135

136+
fn humanize(duration: Duration) -> String {
137+
let duration = duration.to_std().expect("non-negative duration");
138+
if duration.as_secs() < 60 {
139+
format!("{:?}", duration)
140+
} else if duration.as_secs() < 60 * 60 {
141+
format!("{} minutes", duration.as_secs() / 60)
142+
} else {
143+
format!("{:.1} hours", duration.as_secs_f64() / 60.0 / 60.0)
144+
}
145+
}
146+
137147
pub fn endpoint_experiment(name: String, data: Arc<Data>) -> Fallible<Response<Body>> {
138148
if let Some(ex) = Experiment::get(&data.db, &name)? {
139149
let (completed_jobs, total_jobs) = ex.raw_progress(&data.db)?;
@@ -146,43 +156,31 @@ pub fn endpoint_experiment(name: String, data: Arc<Data>) -> Fallible<Response<B
146156
let mut result_counts = result_counts.into_iter().collect::<Vec<_>>();
147157
result_counts.sort_by(|v1, v2| (v1.0).cmp(&v2.0));
148158

149-
let (duration, estimated_end, average_job_duration) = if completed_jobs > 0
150-
&& total_jobs > 0
151-
{
152-
if let Some(started_at) = ex.started_at {
153-
let res = if let Some(completed_at) = ex.completed_at {
154-
let total = completed_at.signed_duration_since(started_at);
155-
(Some(total), None, total / completed_jobs as i32)
156-
} else {
157-
let total = Utc::now().signed_duration_since(started_at);
158-
let job_duration = total / completed_jobs as i32;
159-
(
160-
None,
161-
Some(job_duration * (total_jobs as i32 - completed_jobs as i32)),
162-
job_duration,
163-
)
164-
};
165-
166-
let job_duration = if res.2 < Duration::seconds(3) {
167-
let job_duration = res.2.to_std().expect("negative job time");
168-
format!("{:.2?}", job_duration)
159+
let (duration, estimated_end, average_job_duration) =
160+
if completed_jobs > 0 && total_jobs > 0 {
161+
if let Some(started_at) = ex.started_at {
162+
let res = if let Some(completed_at) = ex.completed_at {
163+
let total = completed_at.signed_duration_since(started_at);
164+
(Some(total), None, total / completed_jobs as i32)
165+
} else {
166+
let total = Utc::now().signed_duration_since(started_at);
167+
let job_duration = total / completed_jobs as i32;
168+
(
169+
None,
170+
Some(job_duration * (total_jobs as i32 - completed_jobs as i32)),
171+
job_duration,
172+
)
173+
};
174+
175+
let job_duration = humanize(res.2);
176+
177+
(res.0.map(humanize), res.1.map(humanize), Some(job_duration))
169178
} else {
170-
HumanTime::from(res.2).to_text_en(Accuracy::Precise, Tense::Present)
171-
};
172-
173-
(
174-
res.0
175-
.map(|r| HumanTime::from(r).to_text_en(Accuracy::Rough, Tense::Present)),
176-
res.1
177-
.map(|r| HumanTime::from(r).to_text_en(Accuracy::Rough, Tense::Present)),
178-
Some(job_duration),
179-
)
179+
(None, None, None)
180+
}
180181
} else {
181182
(None, None, None)
182-
}
183-
} else {
184-
(None, None, None)
185-
};
183+
};
186184

187185
let experiment = ExperimentExt {
188186
common: ExperimentData::new(&data, &ex)?,

0 commit comments

Comments
 (0)