Skip to content

Commit

Permalink
add wsi_retry_limit
Browse files Browse the repository at this point in the history
  • Loading branch information
trueharuu committed Jun 26, 2024
1 parent 0c9e41a commit 47c9fab
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions assyst-common/src/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,5 @@ pub struct DevAttributes {
pub dev_guild: u64,
pub dev_channel: u64,
pub dev_message: bool,
pub wsi_retry_limit: u64,
}
5 changes: 5 additions & 0 deletions assyst-core/src/wsi_handler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,20 @@ impl WsiHandler {
let socket = socket.to_owned();

spawn(async move {
let mut retries = 0;
loop {
let stream = match TcpStream::connect(&socket).await {
Ok(stream) => stream,
Err(e) => {
if retries > CONFIG.dev.wsi_retry_limit {
break;
}
err!(
"Failed to connect to WSI server ({}), attempting reconnection in 10 sec...",
e.to_string()
);
sleep(Duration::from_secs(10)).await;
retries += 1;
continue;
},
};
Expand Down
3 changes: 3 additions & 0 deletions config.template.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,6 @@ dev_guild = 0

# The channel to send the dev message in.
dev_channel = 0

# The amount of times we try connecting to WSI before giving up after failure.
wsi_retry_limit = 50

0 comments on commit 47c9fab

Please sign in to comment.