Skip to content

Commit

Permalink
tasks: improve overall performance overhead from running tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
domenkozar committed Sep 30, 2024
1 parent f990400 commit 4ed8eea
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,10 @@ tracing = "0.1.40"
which = "6.0.0"
whoami = "1.5.1"
xdg = "2.5.2"
tokio = "1.39.3"
tokio = { version = "1.39.3", features = [
"process",
"fs",
"macros",
"rt-multi-thread",
] }
schemars = "0.8.16"
6 changes: 1 addition & 5 deletions devenv/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@ tempdir.workspace = true
tempfile = "3.12.0"
test-log = { version = "0.2.16", features = ["trace"] }
thiserror = "1.0.63"
tokio = { version = "1.39.3", features = [
"process",
"macros",
"rt-multi-thread",
] }
tokio.workspace = true
tracing.workspace = true
which.workspace = true
whoami.workspace = true
Expand Down
26 changes: 16 additions & 10 deletions devenv/src/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use std::fmt::Display;
use std::process::Stdio;
use std::sync::Arc;
use thiserror::Error;
use tokio::fs::File;
use tokio::io::AsyncReadExt;
use tokio::process::Command;
use tokio::sync::RwLock;
use tokio::task::JoinSet;
Expand Down Expand Up @@ -200,10 +202,14 @@ impl TaskState {
(command, outputs_file)
}

fn get_outputs(outputs_file: &tempfile::NamedTempFile) -> Output {
let output = match std::fs::File::open(outputs_file.path()) {
// TODO: report JSON parsing errors
Ok(file) => serde_json::from_reader(file).ok(),
async fn get_outputs(outputs_file: &tempfile::NamedTempFile) -> Output {
let output = match File::open(outputs_file.path()).await {
Ok(mut file) => {
let mut contents = String::new();
// TODO: report JSON parsing errors
file.read_to_string(&mut contents).await.ok();
serde_json::from_str(&contents).ok()
}
Err(_) => None,
};
Output(output)
Expand All @@ -222,9 +228,9 @@ impl TaskState {
match result {
Ok(status) => {
if status.success() {
return TaskCompleted::Skipped(Skipped::Cached(Self::get_outputs(
&outputs_file,
)));
return TaskCompleted::Skipped(Skipped::Cached(
Self::get_outputs(&outputs_file).await,
));
}
}
Err(e) => {
Expand Down Expand Up @@ -322,7 +328,7 @@ impl TaskState {
match result {
Ok(status) => {
if status.success() {
return TaskCompleted::Success(now.elapsed(), Self::get_outputs(&outputs_file));
return TaskCompleted::Success(now.elapsed(), Self::get_outputs(&outputs_file).await);
} else {
return TaskCompleted::Failed(
now.elapsed(),
Expand Down Expand Up @@ -535,7 +541,7 @@ impl Tasks {
break;
}

tokio::time::sleep(std::time::Duration::from_millis(50)).await;
tokio::time::sleep(std::time::Duration::from_millis(10)).await;
}

if dependency_failed {
Expand Down Expand Up @@ -809,7 +815,7 @@ impl TasksUi {
last_list_height = tasks_status.lines.len() as u16 + 1;

// Sleep briefly to avoid excessive redraws
tokio::time::sleep(std::time::Duration::from_millis(50)).await;
tokio::time::sleep(std::time::Duration::from_millis(10)).await;
}

let errors = {
Expand Down

0 comments on commit 4ed8eea

Please sign in to comment.