Skip to content

Commit

Permalink
adding retry to logic that tries to get the config from the Statsig API
Browse files Browse the repository at this point in the history
  • Loading branch information
Leulz committed Jan 26, 2024
1 parent 806e054 commit 3a62d6f
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 27 deletions.
128 changes: 109 additions & 19 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "statsig-rs"
version = "0.7.0"
version = "0.7.1"
edition = "2021"
description = "Unofficial crate to interact with statsig.io"
repository = "https://github.com/reidopitaco/statsig-rs"
Expand All @@ -24,6 +24,7 @@ serde_with = { version = "2.0", features = ["json"] }
sha2 = "0.10"
tokio = { version = "1", features = ["full"] }
tracing = { "version" = "0.1" }
tokio-retry = "0.3.0"


[dev-dependencies]
Expand Down
25 changes: 18 additions & 7 deletions src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ use reqwest::{
};
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use tokio::time::Duration;
use tokio_retry::{
strategy::{jitter, ExponentialBackoff},
Retry,
};

use crate::{
evaluator::models::ConfigData,
Expand Down Expand Up @@ -225,13 +229,20 @@ impl StatsigHttpClient {
sdk_version: RUST_SDK_VERSION,
};

let response = self
.http_client
.post(url)
.timeout(Duration::from_secs(10))
.json(&body)
.send()
.await;
let retry_strategy = ExponentialBackoff::from_millis(1)
.factor(5)
.max_delay(Duration::from_secs(10))
.map(jitter)
.take(5);
let response = Retry::spawn(retry_strategy, || async {
self.http_client
.post(url.clone())
.timeout(Duration::from_secs(10))
.json(&body)
.send()
.await
})
.await;
let res = match response {
Ok(result) => match result.status() {
StatusCode::OK => Ok(result),
Expand Down

0 comments on commit 3a62d6f

Please sign in to comment.