Skip to content

Commit 23fd9b2

Browse files
committed
Get web ui to obey signals
1 parent 1f3e035 commit 23fd9b2

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

crates/turborepo-lib/src/commands/run.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub async fn run(base: CommandBase, telemetry: CommandEventBuilder) -> Result<i3
4545
.build(&handler, telemetry)
4646
.await?;
4747

48-
let (sender, handle) = run.start_web_ui()?.unzip();
48+
let (sender, handle) = run.start_web_ui(&handler)?.unzip();
4949

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

crates/turborepo-lib/src/run/mod.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,23 @@ impl Run {
187187

188188
pub fn start_web_ui(
189189
&self,
190+
signal_handler: &SignalHandler,
190191
) -> Result<Option<(WebUISender, JoinHandle<Result<(), wui::Error>>)>, Error> {
192+
let subscriber = signal_handler
193+
.subscribe()
194+
.ok_or(Error::SignalHandler(std::io::ErrorKind::BrokenPipe.into()))?;
191195
let (tx, rx) = tokio::sync::broadcast::channel(100);
192-
let handle = tokio::spawn(turborepo_ui::wui::start_ws_server(rx));
196+
197+
let handle = tokio::spawn(async {
198+
select! {
199+
_ = turborepo_ui::wui::start_ws_server(rx) => Ok(()),
200+
_ = subscriber.listen() => {
201+
println!("shutting down");
202+
Ok(())
203+
}
204+
}
205+
});
206+
193207
Ok(Some((WebUISender { tx }, handle)))
194208
}
195209

crates/turborepo-ui/src/wui/mod.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -188,15 +188,13 @@ async fn handle_socket_inner(mut socket: WebSocket, state: AppState) -> Result<(
188188
})?;
189189

190190
state.messages.push((event, id));
191-
println!("1");
192191
socket.send(Message::Text(message_payload)).await?;
193192
}
194193
// Every 100ms, check if we need to resend any messages
195194
_ = interval.tick() => {
196195
for (event, id) in &state.messages {
197196
if !state.acks.contains(&id) {
198197
let message_payload = serde_json::to_string(event).unwrap();
199-
println!("2");
200198
socket.send(Message::Text(message_payload)).await?;
201199
}
202200
};
@@ -245,7 +243,7 @@ pub async fn start_ws_server(
245243
});
246244

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

251249
Ok(())

web-ui/app/task-logs.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export default function TaskLogs() {
4848
};
4949

5050
socketRef.current.onopen = () => {
51+
console.log("connected!");
5152
setConnected(true);
5253
};
5354
}

0 commit comments

Comments
 (0)