Skip to content

Commit

Permalink
Added specific symbol for cache hit
Browse files Browse the repository at this point in the history
  • Loading branch information
NicholasLYang committed Jul 29, 2024
1 parent 64e5946 commit 523e3e9
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
7 changes: 4 additions & 3 deletions crates/turborepo-lib/src/task_graph/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,8 @@ impl ExecContext {
// If the task resulted in an error, do not group in order to better highlight
// the error.
let is_error = matches!(result, Ok(ExecOutcome::Task { .. }));
let logs = match output_client.finish(is_error) {
let is_cache_hit = matches!(result, Ok(ExecOutcome::Success(SuccessOutcome::CacheHit)));
let logs = match output_client.finish(is_error, is_cache_hit) {
Ok(logs) => logs,
Err(e) => {
telemetry.track_error(TrackedErrors::DaemonFailedToMarkOutputsAsCached);
Expand Down Expand Up @@ -1136,11 +1137,11 @@ impl<W: Write> CacheOutput for TaskCacheOutput<W> {

/// Struct for displaying information about task
impl<W: Write> TaskOutput<W> {
pub fn finish(self, use_error: bool) -> std::io::Result<Option<Vec<u8>>> {
pub fn finish(self, use_error: bool, is_cache_hit: bool) -> std::io::Result<Option<Vec<u8>>> {
match self {
TaskOutput::Direct(client) => client.finish(use_error),
TaskOutput::UI(client) if use_error => Ok(Some(client.failed())),
TaskOutput::UI(client) => Ok(Some(client.succeeded())),
TaskOutput::UI(client) => Ok(Some(client.succeeded(is_cache_hit))),
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/turborepo-ui/src/tui/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ pub enum Event {
pub enum TaskResult {
Success,
Failure,
CacheHit,
}

#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)]
Expand Down
8 changes: 6 additions & 2 deletions crates/turborepo-ui/src/tui/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,12 @@ impl TuiTask {
}

/// Mark the task as finished
pub fn succeeded(&self) -> Vec<u8> {
self.finish(TaskResult::Success)
pub fn succeeded(&self, is_cache_hit: bool) -> Vec<u8> {
if is_cache_hit {
self.finish(TaskResult::CacheHit)
} else {
self.finish(TaskResult::Success)
}
}

/// Mark the task as finished
Expand Down
23 changes: 18 additions & 5 deletions crates/turborepo-ui/src/tui/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,26 @@ impl<'b> TaskTable<'b> {

fn finished_rows(&self) -> impl Iterator<Item = Row> + '_ {
self.tasks_by_type.finished.iter().map(move |task| {
let name = if matches!(task.result(), TaskResult::CacheHit) {
Cell::new(Text::styled(task.name(), Style::default().italic()))
} else {
Cell::new(task.name())
};

Row::new(vec![
Cell::new(task.name()),
Cell::new(match task.result() {
name,
match task.result() {
// matches Next.js (and many other CLI tools) https://github.com/vercel/next.js/blob/1a04d94aaec943d3cce93487fea3b8c8f8898f31/packages/next/src/build/output/log.ts
TaskResult::Success => Text::styled("✓", Style::default().green().bold()),
TaskResult::Failure => Text::styled("⨯", Style::default().red().bold()),
}),
TaskResult::Success => {
Cell::new(Text::styled("✓", Style::default().green().bold()))
}
TaskResult::CacheHit => {
Cell::new(Text::styled("⊙", Style::default().magenta()))
}
TaskResult::Failure => {
Cell::new(Text::styled("⨯", Style::default().red().bold()))
}
},
])
})
}
Expand Down

0 comments on commit 523e3e9

Please sign in to comment.