Skip to content

Commit

Permalink
Chore(1-3208): add feature refresher mode to avoid strict dynamic issues
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasheartman committed Dec 18, 2024
1 parent 9d66bfd commit f96b70e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
10 changes: 7 additions & 3 deletions server/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use unleash_yggdrasil::EngineState;

use crate::cli::RedisMode;
use crate::feature_cache::FeatureCache;
use crate::http::feature_refresher::FeatureRefreshConfig;
use crate::http::feature_refresher::{FeatureRefreshConfig, FeatureRefresherMode};
use crate::http::unleash_client::new_reqwest_client;
use crate::offline::offline_hotload::{load_bootstrap, load_offline_engine_cache};
use crate::persistence::file::FilePersister;
Expand Down Expand Up @@ -259,10 +259,14 @@ async fn build_edge(args: &EdgeArgs, app_name: &str) -> EdgeResult<EdgeInfo> {
unleash_client: unleash_client.clone(),
persistence: persistence.clone(),
});
let refresher_mode = match (args.strict, args.streaming) {
(_, true) => FeatureRefresherMode::Streaming,
(true, _) => FeatureRefresherMode::Strict,
_ => FeatureRefresherMode::Dynamic,
};
let feature_config = FeatureRefreshConfig::new(
Duration::seconds(args.features_refresh_interval_seconds as i64),
args.streaming,
args.strict,
refresher_mode,
app_name.to_string(),
);
let feature_refresher = Arc::new(FeatureRefresher::new(
Expand Down
20 changes: 12 additions & 8 deletions server/src/http/feature_refresher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,24 +86,28 @@ fn client_application_from_token_and_name(
}
}

#[derive(Eq, PartialEq)]
pub enum FeatureRefresherMode {
Dynamic,
Streaming,
Strict,
}

pub struct FeatureRefreshConfig {
features_refresh_interval: chrono::Duration,
strict: bool,
streaming: bool,
mode: FeatureRefresherMode,
app_name: String,
}

impl FeatureRefreshConfig {
pub fn new(
features_refresh_interval: chrono::Duration,
strict: bool,
streaming: bool,
mode: FeatureRefresherMode,
app_name: String,
) -> Self {
Self {
features_refresh_interval,
strict,
streaming,
mode,
app_name,
}
}
Expand All @@ -124,8 +128,8 @@ impl FeatureRefresher {
engine_cache: engines,
refresh_interval: config.features_refresh_interval,
persistence,
strict: config.strict,
streaming: config.streaming,
strict: config.mode != FeatureRefresherMode::Dynamic,
streaming: config.mode == FeatureRefresherMode::Streaming,
app_name: config.app_name,
}
}
Expand Down

0 comments on commit f96b70e

Please sign in to comment.