Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: features get refreshed. #38

Merged
merged 1 commit into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion server/src/frontend_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ fn resolve_frontend_features(
}

pub fn configure_frontend_api(cfg: &mut web::ServiceConfig) {
cfg.service(get_frontend_features);
cfg.service(get_frontend_features)
.service(post_enabled_frontend_features)
.service(post_frontend_features)
.service(post_enabled_frontend_features);
}

#[cfg(test)]
Expand Down
51 changes: 25 additions & 26 deletions server/src/http/background_refresh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,36 +36,35 @@ pub async fn poll_for_token_status(
pub async fn refresh_features(mut channel: Receiver<EdgeToken>, sink: Arc<RwLock<dyn EdgeSink>>) {
let mut tokens = HashSet::new();
loop {
let token = channel.recv().await;
if let Some(token) = token {
tokens.insert(token);

let mut write_lock = sink.write().await;
for token in tokens.iter() {
let features_result = write_lock.fetch_features(token).await;
match features_result {
Ok(feature_response) => match feature_response {
ClientFeaturesResponse::NoUpdate(_) => info!("No update needed"),
ClientFeaturesResponse::Updated(features, _) => {
let sink_result = write_lock.sink_features(token, features).await;
if let Err(err) = sink_result {
warn!("Failed to sink features in updater {err:?}");
tokio::select! {
token = channel.recv() => { // Got a new token
if let Some(token) = token {
tokens.insert(token);
} else {
break;
}
},
_ = tokio::time::sleep(Duration::from_secs(10)) => { // Iterating over known tokens
let mut write_lock = sink.write().await;
info!("Updating features for known tokens");
for token in tokens.iter() {
let features_result = write_lock.fetch_features(token).await;
match features_result {
Ok(feature_response) => match feature_response {
ClientFeaturesResponse::NoUpdate(_) => info!("No update needed"),
ClientFeaturesResponse::Updated(features, _) => {
let sink_result = write_lock.sink_features(token, features).await;
if let Err(err) = sink_result {
warn!("Failed to sink features in updater {err:?}");
}
}
},
Err(e) => {
warn!("Couldn't refresh features: {e:?}");
}
},
Err(e) => {
warn!("Couldn't refresh features: {e:?}");
}
}
}
} else {
break;
},
}

tokio::select! {
_ = tokio::time::sleep(Duration::from_secs(15)) => {
continue;
}
};
}
}
2 changes: 1 addition & 1 deletion server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use actix_cors::Cors;

use actix_middleware_etag::Etag;
use actix_web::middleware::Logger;
use actix_web::{http, web, App, HttpServer};
use actix_web::{web, App, HttpServer};
use actix_web_opentelemetry::RequestTracing;
use clap::Parser;
use cli::CliArgs;
Expand Down