Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
sharkAndshark committed Jun 3, 2024
1 parent 0d24767 commit 7440428
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
1 change: 1 addition & 0 deletions martin/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use crate::{IdResolver, MartinResult, OptOneMany};

pub type UnrecognizedValues = HashMap<String, serde_yaml::Value>;

#[derive(Clone)]
pub struct ServerState {
pub cache: OptMainCache,
pub tiles: TileSources,
Expand Down
24 changes: 22 additions & 2 deletions martin/src/srv/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -84,7 +87,18 @@ async fn refresh_catalog(
args: Data<Args>,
env: Data<OsEnv>,
srv_config_guard: Data<RwLock<SrvConfig>>,
catalog_guard: Data<RwLock<Catalog>>,
state_guard: Data<RwLock<ServerState>>,
tiles_guard: Data<RwLock<TileSources>>,
cache_guard: Data<RwLock<OptMainCache>>,

#[cfg(feature = "sprites")]
sprites_guard: Data<RwLock<SpriteSources>>,

#[cfg(feature = "fonts")]
fonts_guard: Data<RwLock<FontSources>>,


) -> actix_web::error::Result<HttpResponse> {
let mut config = if let Some(ref cfg_filename) = args.meta.config {
info!("Using {} to refresh catalog", cfg_filename.display());
Expand All @@ -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;

Expand All @@ -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);

Expand Down Expand Up @@ -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())));
Expand Down
2 changes: 1 addition & 1 deletion tests/config-for-refresh.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion tests/test-refresh.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 7440428

Please sign in to comment.