Skip to content

Commit

Permalink
Get web ui to obey signals
Browse files Browse the repository at this point in the history
  • Loading branch information
NicholasLYang committed Aug 2, 2024
1 parent 1f3e035 commit 23fd9b2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion crates/turborepo-lib/src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub async fn run(base: CommandBase, telemetry: CommandEventBuilder) -> Result<i3
.build(&handler, telemetry)
.await?;

let (sender, handle) = run.start_web_ui()?.unzip();
let (sender, handle) = run.start_web_ui(&handler)?.unzip();

Check warning on line 48 in crates/turborepo-lib/src/commands/run.rs

View workflow job for this annotation

GitHub Actions / Turborepo rust check

unused variable: `handle`

Check warning on line 48 in crates/turborepo-lib/src/commands/run.rs

View workflow job for this annotation

GitHub Actions / Build Turborepo (ubuntu, self-hosted, linux, x64, metal)

unused variable: `handle`

Check warning on line 48 in crates/turborepo-lib/src/commands/run.rs

View workflow job for this annotation

GitHub Actions / Build Turborepo (macos, macos-12)

unused variable: `handle`

Check warning on line 48 in crates/turborepo-lib/src/commands/run.rs

View workflow job for this annotation

GitHub Actions / Build Turborepo (windows, windows-latest)

unused variable: `handle`

Check warning on line 48 in crates/turborepo-lib/src/commands/run.rs

View workflow job for this annotation

GitHub Actions / Turborepo Integration (ubuntu-latest)

unused variable: `handle`

Check warning on line 48 in crates/turborepo-lib/src/commands/run.rs

View workflow job for this annotation

GitHub Actions / Turborepo Integration (macos-12)

unused variable: `handle`

Check warning on line 48 in crates/turborepo-lib/src/commands/run.rs

View workflow job for this annotation

GitHub Actions / Turborepo Integration (windows-latest)

unused variable: `handle`

let result = run.run(sender.clone(), false).await;

Expand Down
16 changes: 15 additions & 1 deletion crates/turborepo-lib/src/run/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,23 @@ impl Run {

pub fn start_web_ui(
&self,
signal_handler: &SignalHandler,
) -> Result<Option<(WebUISender, JoinHandle<Result<(), wui::Error>>)>, Error> {
let subscriber = signal_handler
.subscribe()
.ok_or(Error::SignalHandler(std::io::ErrorKind::BrokenPipe.into()))?;
let (tx, rx) = tokio::sync::broadcast::channel(100);
let handle = tokio::spawn(turborepo_ui::wui::start_ws_server(rx));

let handle = tokio::spawn(async {
select! {
_ = turborepo_ui::wui::start_ws_server(rx) => Ok(()),
_ = subscriber.listen() => {
println!("shutting down");
Ok(())
}
}
});

Ok(Some((WebUISender { tx }, handle)))
}

Expand Down
4 changes: 1 addition & 3 deletions crates/turborepo-ui/src/wui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,13 @@ async fn handle_socket_inner(mut socket: WebSocket, state: AppState) -> Result<(
})?;

state.messages.push((event, id));
println!("1");
socket.send(Message::Text(message_payload)).await?;
}
// Every 100ms, check if we need to resend any messages
_ = interval.tick() => {
for (event, id) in &state.messages {
if !state.acks.contains(&id) {

Check failure on line 196 in crates/turborepo-ui/src/wui/mod.rs

View workflow job for this annotation

GitHub Actions / Turborepo rust clippy

this expression creates a reference which is immediately dereferenced by the compiler
let message_payload = serde_json::to_string(event).unwrap();
println!("2");
socket.send(Message::Text(message_payload)).await?;
}
};
Expand Down Expand Up @@ -245,7 +243,7 @@ pub async fn start_ws_server(
});

let listener = tokio::net::TcpListener::bind("127.0.0.1:1337").await?;
println!("Web UI listening on port 1337");
println!("Web UI listening on port 1337...");
axum::serve(listener, app).await?;

Ok(())
Expand Down
1 change: 1 addition & 0 deletions web-ui/app/task-logs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export default function TaskLogs() {
};

socketRef.current.onopen = () => {
console.log("connected!");
setConnected(true);
};
}
Expand Down

0 comments on commit 23fd9b2

Please sign in to comment.