Skip to content
This repository was archived by the owner on Aug 9, 2022. It is now read-only.

Commit 46a8076

Browse files
authored
chore: update deps and add more logs (#59)
* chore: update deps and add more logs * add misc
1 parent 35036b2 commit 46a8076

File tree

6 files changed

+88
-59
lines changed

6 files changed

+88
-59
lines changed

Cargo.lock

Lines changed: 42 additions & 42 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bin/config-template.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ max_cap_per_subscription = 64
1010
[nodes.polkadot]
1111
url = "wss://rpc.polkadot.io"
1212
# kusama config
13-
[nodes.kusama]
14-
url = "wss://kusama-rpc.polkadot.io"
13+
#[nodes.kusama]
14+
#url = "wss://kusama-rpc.polkadot.io"

src/lib.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@ pub mod cmd;
22
pub mod compression;
33
pub mod config;
44
pub mod message;
5+
mod misc;
56
pub mod rpc_client;
67
pub mod session;
78
pub mod substrate;
89
pub mod websocket;
10+
911
use anyhow::Result;
1012
use futures::StreamExt;
13+
pub use misc::*;
1114
use serde::{Deserialize, Serialize};
1215
use std::{sync::Arc, time::Duration};
1316
use tokio::sync::RwLock;
@@ -205,14 +208,16 @@ async fn handle_connection(connection: WsConnection) {
205208
Message::Binary(_) => {}
206209

207210
Message::Close(_) => {
208-
let _res = connection.send_close().await;
211+
let res = connection.send_close().await;
212+
handle_result(res, "handle close message");
209213
break;
210214
}
211215

212216
Message::Ping(_) => {
213-
let _res = connection
217+
let res = connection
214218
.send_message(Message::Pong(b"pong".to_vec()))
215219
.await;
220+
handle_result(res, "handle ping message");
216221
}
217222

218223
Message::Text(s) => {

src/misc.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
use tokio_tungstenite::tungstenite;
2+
3+
pub fn handle_result<T>(res: tungstenite::Result<T>, when: impl AsRef<str>) {
4+
if let Err(err) = res {
5+
log::warn!("Error occurred when {}: {:?}", when.as_ref(), err);
6+
}
7+
}

src/rpc_client.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,17 @@ impl RpcClient {
9999

100100
#[inline]
101101
pub async fn is_alive(&self) -> bool {
102-
self.system_health().await.is_ok()
102+
let output = self.system_health().await;
103+
match output {
104+
Err(err) => {
105+
log::info!("system_health failed for '{}': {:?}", self.chain, err);
106+
false
107+
}
108+
Ok(output) => {
109+
log::info!("system_health check for '{}': {}", self.chain, output);
110+
true
111+
}
112+
}
103113
}
104114

105115
// After `reconnect`ed, client need to re`subscribe`.

0 commit comments

Comments
 (0)