Skip to content

Commit

Permalink
fix(worker): try to fix websocket start useless thread
Browse files Browse the repository at this point in the history
  • Loading branch information
eatradish committed Jun 30, 2024
1 parent fe02e81 commit b62f222
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions worker/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use tokio::{
fs,
io::{AsyncBufReadExt, AsyncRead, BufReader},
process::Command,
select,
time::sleep,
};
use tokio_tungstenite::{connect_async, tungstenite::Message};
Expand Down Expand Up @@ -409,10 +410,22 @@ async fn build_worker_inner(args: &Args) -> anyhow::Result<()> {

let (tx, rx) = unbounded();

tokio::spawn(async move {
websocket_connect(rx, ws).await;
});
select! { res = poll_server(client, args, req, tree_path, tx) => {
warn!("{res:?}");
res
}, res = websocket_connect(rx, ws) => {
warn!("{res:?}");
res
} }
}

async fn poll_server(
client: reqwest::Client,
args: &Args,
req: WorkerPollRequest,
tree_path: std::path::PathBuf,
tx: Sender<Message>,
) -> Result<(), anyhow::Error> {
loop {
if let Some(job) = client
.post(format!("{}/api/worker/poll", args.server))
Expand Down Expand Up @@ -464,7 +477,7 @@ pub async fn build_worker(args: Args) -> ! {
}
}

pub async fn websocket_connect(rx: Receiver<Message>, ws: Url) -> ! {
pub async fn websocket_connect(rx: Receiver<Message>, ws: Url) -> anyhow::Result<()> {
loop {
info!("Starting websocket connect to {:?}", ws);
match connect_async(ws.as_str()).await {
Expand Down

0 comments on commit b62f222

Please sign in to comment.