Skip to content

Commit

Permalink
reduce nesting in track_logs
Browse files Browse the repository at this point in the history
  • Loading branch information
JssDWt committed Nov 7, 2024
1 parent fc8fdb7 commit 2a6b750
Showing 1 changed file with 33 additions and 26 deletions.
59 changes: 33 additions & 26 deletions libs/sdk-core/src/breez_services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1764,38 +1764,45 @@ impl BreezServices {
if shutdown_receiver.has_changed().unwrap_or(true) {
return;
}
let log_stream_res = cloned.node_api.stream_log_messages().await;
if let Ok(mut log_stream) = log_stream_res {
loop {
tokio::select! {
log_message_res = log_stream.message() => {
match log_message_res {
Ok(Some(l)) => {
info!("node-logs: {}", l.line);
},
// stream is closed, renew it
Ok(None) => {
break;
}
Err(err) => {
debug!("failed to process log entry {:?}", err);
break;
}
};
}
let mut log_stream = match cloned.node_api.stream_log_messages().await {
Ok(log_stream) => log_stream,
Err(e) => {
warn!("stream log messages returned error: {:?}", e);
sleep(Duration::from_secs(1)).await;
continue;
}
};

loop {
let log_message_res = tokio::select! {
log_message_res = log_stream.message() => {
log_message_res
}

_ = shutdown_receiver.changed() => {
debug!("Track logs task has completed");
return;
}
_ = shutdown_receiver.changed() => {
debug!("Track logs task has completed");
return;
}

_ = reconnect_receiver.changed() => {
_ = reconnect_receiver.changed() => {
debug!("Reconnect hibernation: track logs");
break;
}
}
}
};

match log_message_res {
Ok(Some(l)) => info!("node-logs: {}", l.line),
Ok(None) => {
// stream is closed, renew it
break;
}
Err(err) => {
debug!("failed to process log entry {:?}", err);
break;
}
};
}

sleep(Duration::from_secs(1)).await;
}
});
Expand Down

0 comments on commit 2a6b750

Please sign in to comment.