fix(local): ServerScore push_score maintain compatibility

This commit is contained in:
zonyitoo
2024-06-23 22:53:54 +08:00
parent 6c5f8f2a51
commit 03e9e95f69
2 changed files with 14 additions and 4 deletions
@@ -824,9 +824,9 @@ impl PingChecker {
};
let (score, stat_data) = match self.check_delay().await {
Ok(d) => server_score.push_score(Score::Latency(d)).await,
Ok(d) => server_score.push_score_fetch_statistic(Score::Latency(d)).await,
// Penalty
Err(..) => server_score.push_score(Score::Errored).await,
Err(..) => server_score.push_score_fetch_statistic(Score::Errored).await,
};
if stat_data.fail_rate > 0.5 {
@@ -40,7 +40,17 @@ impl ServerScore {
}
/// Append a `Score` into statistic and recalculate score of the server
pub async fn push_score(&self, score: Score) -> (u32, ServerStatData) {
pub async fn push_score(&self, score: Score) -> u32 {
let updated_score = {
let mut stat = self.stat_data.lock().await;
stat.push_score(score)
};
self.score.store(updated_score, Ordering::Release);
updated_score
}
/// Append a `Score` into statistic and recalculate score of the server
pub async fn push_score_fetch_statistic(&self, score: Score) -> (u32, ServerStatData) {
let (updated_score, data) = {
let mut stat = self.stat_data.lock().await;
(stat.push_score(score), stat.data().clone())
@@ -50,7 +60,7 @@ impl ServerScore {
}
/// Report request failure of this server, which will eventually records an `Errored` score
pub async fn report_failure(&self) -> (u32, ServerStatData) {
pub async fn report_failure(&self) -> u32 {
self.push_score(Score::Errored).await
}