diff --git a/martin/src/config.rs b/martin/src/config.rs index 8be723a91..9e95afd94 100644 --- a/martin/src/config.rs +++ b/martin/src/config.rs @@ -25,6 +25,7 @@ use crate::{IdResolver, MartinResult, OptOneMany}; pub type UnrecognizedValues = HashMap; +#[derive(Clone)] pub struct ServerState { pub cache: OptMainCache, pub tiles: TileSources, diff --git a/martin/src/srv/server.rs b/martin/src/srv/server.rs index 50fc81b1c..f4f4e2533 100755 --- a/martin/src/srv/server.rs +++ b/martin/src/srv/server.rs @@ -5,7 +5,10 @@ use std::time::Duration; use crate::args::{Args, OsEnv}; use crate::config::ServerState; -use crate::read_config; +use crate::fonts::FontSources; +use crate::sprites::SpriteSources; +use crate::utils::OptMainCache; +use crate::{read_config, TileSources}; use crate::source::TileCatalog; use crate::srv::config::{SrvConfig, KEEP_ALIVE_DEFAULT, LISTEN_ADDRESSES_DEFAULT}; use crate::srv::tiles::get_tile; @@ -84,7 +87,18 @@ async fn refresh_catalog( args: Data, env: Data, srv_config_guard: Data>, + catalog_guard: Data>, state_guard: Data>, + tiles_guard: Data>, + cache_guard: Data>, + + #[cfg(feature = "sprites")] + sprites_guard: Data>, + + #[cfg(feature = "fonts")] + fonts_guard: Data>, + + ) -> actix_web::error::Result { let mut config = if let Some(ref cfg_filename) = args.meta.config { info!("Using {} to refresh catalog", cfg_filename.display()); @@ -109,6 +123,10 @@ async fn refresh_catalog( let mut srv_config = srv_config_guard.write().await; let mut state = state_guard.write().await; + + + + *srv_config = new_srv_config; *state = new_state; @@ -131,6 +149,7 @@ pub fn router(cfg: &mut web::ServiceConfig) { cfg.service(get_health) .service(get_index) .service(get_catalog) + .service(refresh_catalog) .service(get_source_info) .service(get_tile); @@ -166,7 +185,8 @@ pub fn new_server( let app = App::new() .app_data(Data::new(RwLock::new(state.tiles.clone()))) - .app_data(Data::new(RwLock::new(state.cache.clone()))); + .app_data(Data::new(RwLock::new(state.cache.clone()))) + .app_data(Data::new(RwLock::new(state.clone()))); #[cfg(feature = "sprites")] let app = app.app_data(Data::new(RwLock::new(state.sprites.clone()))); diff --git a/tests/config-for-refresh.yaml b/tests/config-for-refresh.yaml index 8129894ff..d8214bc62 100644 --- a/tests/config-for-refresh.yaml +++ b/tests/config-for-refresh.yaml @@ -31,4 +31,4 @@ mbtiles: paths: tests/fixtures/mbtiles/webp.mbtiles sources: mbt1: tests/fixtures/mbtiles/world_cities.mbtiles - mbt2: json.mbtiles + mbt2: tests/fixtures/mbtiles/json.mbtiles diff --git a/tests/test-refresh.sh b/tests/test-refresh.sh index a96c2ad4e..f90e57e4f 100755 --- a/tests/test-refresh.sh +++ b/tests/test-refresh.sh @@ -103,7 +103,7 @@ test_jsn catalog_before_refresh catalog # Update config and database cp -f tests/config-for-refresh.yaml /tmp/config.yaml # todo use psql to alter database -curl -X POST "$MARTIN_URL/refresh" +$CURL -X POST "$MARTIN_URL/refresh" # Fetch and verify the catalog json after refresh calling