fix(channels): 飞书频道断线重连改为指数退避无限重试,网络恢复后自愈
This commit is contained in:
parent
4ce89f8d82
commit
664d7e5a15
@ -2308,8 +2308,9 @@ impl Channel for FeishuChannel {
|
|||||||
let channel = self.clone();
|
let channel = self.clone();
|
||||||
let bus = bus.clone();
|
let bus = bus.clone();
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
let mut consecutive_failures = 0;
|
let mut consecutive_failures: u32 = 0;
|
||||||
let max_failures = 3;
|
let base_retry_secs: u64 = 5;
|
||||||
|
let max_retry_secs: u64 = 60;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
if !*channel.running.read().await {
|
if !*channel.running.read().await {
|
||||||
@ -2319,15 +2320,12 @@ impl Channel for FeishuChannel {
|
|||||||
let shutdown_rx = shutdown_tx.subscribe();
|
let shutdown_rx = shutdown_tx.subscribe();
|
||||||
match channel.run_ws_loop(bus.clone(), shutdown_rx).await {
|
match channel.run_ws_loop(bus.clone(), shutdown_rx).await {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
|
consecutive_failures = 0;
|
||||||
tracing::info!("Feishu WebSocket disconnected");
|
tracing::info!("Feishu WebSocket disconnected");
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
consecutive_failures += 1;
|
consecutive_failures = consecutive_failures.saturating_add(1);
|
||||||
tracing::error!(attempt = consecutive_failures, error = %e, "Feishu WebSocket error");
|
tracing::error!(attempt = consecutive_failures, error = %e, "Feishu WebSocket error");
|
||||||
if consecutive_failures >= max_failures {
|
|
||||||
tracing::error!("Feishu channel: max failures reached, stopping");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2335,8 +2333,15 @@ impl Channel for FeishuChannel {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
tracing::info!("Feishu channel retrying in 5s...");
|
let exponent = consecutive_failures.saturating_sub(1).min(6);
|
||||||
tokio::time::sleep(tokio::time::Duration::from_secs(5)).await;
|
let retry_secs = (base_retry_secs * (1u64 << exponent)).min(max_retry_secs);
|
||||||
|
tracing::info!("Feishu channel retrying in {}s...", retry_secs);
|
||||||
|
let mut remaining = retry_secs;
|
||||||
|
while remaining > 0 && *channel.running.read().await {
|
||||||
|
let step = remaining.min(base_retry_secs);
|
||||||
|
tokio::time::sleep(tokio::time::Duration::from_secs(step)).await;
|
||||||
|
remaining -= step;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*channel.running.write().await = false;
|
*channel.running.write().await = false;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user