Skip to content

Commit

Permalink
fix(ui): always start tasks (#7758)
Browse files Browse the repository at this point in the history
### Description

Was hitting failures on cache hits where we would try to mark a task as
finished, but we had never started it. This PR makes sure we start tasks
in the UI even on cache hits.

Added some debug logging to help distinguish the "task not found in ui"
errors.

### Testing Instructions

Use the UI with a `turbo` run with a cache hit.


Closes TURBO-2653
  • Loading branch information
chris-olszewski authored Mar 19, 2024
1 parent 0fc0fc2 commit d0383d5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
8 changes: 7 additions & 1 deletion crates/turborepo-lib/src/task_graph/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,12 @@ impl ExecContext {
self.pretty_prefix.clone(),
);

if self.experimental_ui {
if let TaskOutput::UI(task) = output_client {
task.start();
}
}

match self
.task_cache
.restore_outputs(prefixed_ui.output_prefixed_writer(), telemetry)
Expand Down Expand Up @@ -911,9 +917,9 @@ impl ExecContext {
return ExecOutcome::Internal;
}
};

if self.experimental_ui {
if let TaskOutput::UI(task) = output_client {
task.start();
if let Some(stdin) = process.stdin() {
task.set_stdin(stdin);
}
Expand Down
2 changes: 2 additions & 0 deletions crates/turborepo-ui/src/tui/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use ratatui::{
widgets::Widget,
Frame, Terminal,
};
use tracing::debug;
use tui_term::widget::PseudoTerminal;

const HEIGHT: u16 = 60;
Expand All @@ -26,6 +27,7 @@ pub struct App<I> {

impl<I> App<I> {
pub fn new(rows: u16, cols: u16, tasks: Vec<String>) -> Self {
debug!("tasks: {tasks:?}");
let mut this = Self {
table: TaskTable::new(tasks.clone()),
pane: TerminalPane::new(rows, cols, tasks),
Expand Down
5 changes: 4 additions & 1 deletion crates/turborepo-ui/src/tui/pane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use ratatui::{
style::Style,
widgets::{Block, Borders, Widget},
};
use tracing::debug;
use tui_term::widget::PseudoTerminal;
use turborepo_vt100 as vt100;

Expand Down Expand Up @@ -45,7 +46,9 @@ impl<W> TerminalPane<W> {
}

pub fn process_output(&mut self, task: &str, output: &[u8]) -> Result<(), Error> {
let task = self.task_mut(task)?;
let task = self
.task_mut(task)
.inspect_err(|_| debug!("cannot find task on process output"))?;
task.parser.process(output);
Ok(())
}
Expand Down
11 changes: 9 additions & 2 deletions crates/turborepo-ui/src/tui/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use ratatui::{
Block, BorderType, Borders, Cell, Paragraph, Row, StatefulWidget, Table, TableState, Widget,
},
};
use tracing::debug;

use super::{
task::{Finished, Planned, Running, Task},
Expand Down Expand Up @@ -78,7 +79,10 @@ impl TaskTable {
let planned_idx = self
.planned
.binary_search_by(|planned_task| planned_task.name().cmp(task))
.map_err(|_| Error::TaskNotFound { name: task.into() })?;
.map_err(|_| {
debug!("could not find '{task}' to start");
Error::TaskNotFound { name: task.into() }
})?;
let planned = self.planned.remove(planned_idx);
let old_row_idx = self.finished.len() + self.running.len() + planned_idx;
let new_row_idx = self.finished.len() + self.running.len();
Expand Down Expand Up @@ -107,7 +111,10 @@ impl TaskTable {
.running
.iter()
.position(|running| running.name() == task)
.ok_or_else(|| Error::TaskNotFound { name: task.into() })?;
.ok_or_else(|| {
debug!("could not find '{task}' to finish");
Error::TaskNotFound { name: task.into() }
})?;
let old_row_idx = self.finished.len() + running_idx;
let new_row_idx = self.finished.len();
let running = self.running.remove(running_idx);
Expand Down

0 comments on commit d0383d5

Please sign in to comment.