Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: minor task cache changes #5838

Merged
merged 3 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions crates/turborepo-lib/src/run/cache.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{io::Write, rc::Rc};
use std::{io::Write, sync::Arc};

use console::StyledObject;
use tracing::{debug, log::warn};
Expand Down Expand Up @@ -49,15 +49,16 @@ impl RunCache {
}

pub fn task_cache(
self: &Rc<Self>,
self: &Arc<Self>,
// TODO: Group these in a struct
task_definition: &TaskDefinition,
task_dir: &AbsoluteSystemPath,
workspace_dir: &AnchoredSystemPath,
task_id: TaskId<'static>,
log_file: &AnchoredSystemPath,
hash: &str,
) -> TaskCache {
let log_file_path = self.repo_root.resolve(log_file);
let task_dir = self.repo_root.resolve(workspace_dir);
let log_file_path =
task_dir.join_components(&[".turbo", &format!("turbo-{}.log", task_id.task())]);
let hashable_outputs = task_definition.hashable_outputs(&task_id);
let mut repo_relative_globs = TaskOutputs {
inclusions: Vec::with_capacity(hashable_outputs.inclusions.len()),
Expand Down Expand Up @@ -102,7 +103,7 @@ impl RunCache {

pub struct TaskCache {
expanded_outputs: Vec<AnchoredSystemPathBuf>,
run_cache: Rc<RunCache>,
run_cache: Arc<RunCache>,
repo_relative_globs: TaskOutputs,
hash: String,
task_output_mode: OutputLogsMode,
Expand All @@ -114,7 +115,7 @@ pub struct TaskCache {
}

impl TaskCache {
fn replay_log_file(
pub fn replay_log_file(
&self,
prefixed_ui: &mut PrefixedUI<impl Write>,
) -> Result<(), anyhow::Error> {
Expand All @@ -125,7 +126,7 @@ impl TaskCache {
Ok(())
}

fn on_error(&self, prefixed_ui: &mut PrefixedUI<impl Write>) -> Result<(), anyhow::Error> {
pub fn on_error(&self, prefixed_ui: &mut PrefixedUI<impl Write>) -> Result<(), anyhow::Error> {
if self.task_output_mode == OutputLogsMode::ErrorsOnly {
prefixed_ui.output(format!(
"cache miss, executing {}",
Expand All @@ -137,7 +138,7 @@ impl TaskCache {
Ok(())
}

fn output_writer<W: Write>(
pub fn output_writer<W: Write>(
&self,
prefix: StyledObject<String>,
writer: W,
Expand All @@ -162,7 +163,7 @@ impl TaskCache {
Ok(log_writer)
}

async fn restore_outputs(
pub async fn restore_outputs(
&mut self,
team_id: &str,
team_slug: Option<&str>,
Expand Down
4 changes: 2 additions & 2 deletions crates/turborepo-lib/src/run/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ mod cache;
mod global_hash;
mod scope;
pub mod task_id;

use std::{
io::{BufWriter, IsTerminal},
sync::Arc,
};

use anyhow::{anyhow, Context as ErrorContext, Result};
pub use cache::{RunCache, TaskCache};
use itertools::Itertools;
use tracing::{debug, info};
use turbopath::AbsoluteSystemPathBuf;
Expand All @@ -29,7 +29,7 @@ use crate::{
opts::{GraphOpts, Opts},
package_graph::{PackageGraph, WorkspaceName},
package_json::PackageJson,
run::{cache::RunCache, global_hash::get_global_hash_inputs},
run::global_hash::get_global_hash_inputs,
task_graph::Visitor,
};

Expand Down
Loading