mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-04-04 14:29:45 +00:00
fix: Add in the code to create the life check for the ui to keep the … (#2391)
* fix: Add in the code to create the life check for the ui to keep the ws alive * Update Cargo.toml * Update rpc.rs
This commit is contained in:
@@ -14,6 +14,7 @@ use rpc_toolkit::hyper::{Body, Error as HyperError, Request, Response};
|
|||||||
use rpc_toolkit::yajrc::RpcError;
|
use rpc_toolkit::yajrc::RpcError;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
|
use tokio::io::AsyncWrite;
|
||||||
use tokio::sync::oneshot;
|
use tokio::sync::oneshot;
|
||||||
use tokio::task::JoinError;
|
use tokio::task::JoinError;
|
||||||
use tokio_tungstenite::tungstenite::protocol::frame::coding::CloseCode;
|
use tokio_tungstenite::tungstenite::protocol::frame::coding::CloseCode;
|
||||||
@@ -82,6 +83,7 @@ async fn deal_with_messages(
|
|||||||
mut sub: patch_db::Subscriber,
|
mut sub: patch_db::Subscriber,
|
||||||
mut stream: WebSocketStream<Upgraded>,
|
mut stream: WebSocketStream<Upgraded>,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
|
let mut timer = tokio::time::interval(tokio::time::Duration::from_secs(5));
|
||||||
loop {
|
loop {
|
||||||
futures::select! {
|
futures::select! {
|
||||||
_ = (&mut kill).fuse() => {
|
_ = (&mut kill).fuse() => {
|
||||||
@@ -104,14 +106,19 @@ async fn deal_with_messages(
|
|||||||
}
|
}
|
||||||
message = stream.next().fuse() => {
|
message = stream.next().fuse() => {
|
||||||
let message = message.transpose().with_kind(crate::ErrorKind::Network)?;
|
let message = message.transpose().with_kind(crate::ErrorKind::Network)?;
|
||||||
match message {
|
if message.is_none() {
|
||||||
None => {
|
tracing::info!("Closing WebSocket: Stream Finished");
|
||||||
tracing::info!("Closing WebSocket: Stream Finished");
|
return Ok(())
|
||||||
return Ok(())
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// This is trying to give a health checks to the home to keep the ui alive.
|
||||||
|
_ = timer.tick().fuse() => {
|
||||||
|
stream
|
||||||
|
.send(Message::Ping(vec![]))
|
||||||
|
.await
|
||||||
|
.with_kind(crate::ErrorKind::Network)?;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user