diff --git a/src/bin/blog_server/config.rs b/src/bin/blog_server/config.rs index 320237c..2bcf69e 100644 --- a/src/bin/blog_server/config.rs +++ b/src/bin/blog_server/config.rs @@ -1,7 +1,7 @@ -use std::{net::SocketAddr, path::PathBuf, str}; +use std::{time::Duration, net::SocketAddr, path::PathBuf, str}; use libshire::uuid::Uuid; -use serde::Deserialize; +use serde::{Deserialize, Deserializer}; #[derive(Deserialize, Clone, Debug)] pub(crate) struct Config { @@ -12,6 +12,8 @@ pub(crate) struct Config { pub robots_path: PathBuf, pub posts_dir: PathBuf, pub post_media_dir: PathBuf, + #[serde(rename = "fs_event_delay_millis", deserialize_with = "deserialize_millis")] + pub fs_event_delay: Duration, pub namespace_uuid: Uuid, pub self_ref: SelfRefConfig, pub rss: RssConfig, @@ -44,3 +46,11 @@ impl str::FromStr for Config { toml::from_str(s) } } + +fn deserialize_millis<'de, D>(deserializer: D) -> Result +where + D: Deserializer<'de> +{ + u64::deserialize(deserializer) + .map(Duration::from_millis) +} diff --git a/src/bin/blog_server/fs_watcher.rs b/src/bin/blog_server/fs_watcher.rs index 0329299..d9c05ac 100644 --- a/src/bin/blog_server/fs_watcher.rs +++ b/src/bin/blog_server/fs_watcher.rs @@ -17,10 +17,11 @@ use crate::Error; pub(crate) fn start_watching( tx: mpsc::Sender, - watch_path: &Path + watch_path: &Path, + delay: Duration ) -> Result { - let mut watcher = watcher(tx, Duration::from_secs(2)) + let mut watcher = watcher(tx, delay) .map_err(Error::CreateWatcher)?; // Watch the path in non-recursive mode, so events are not generated for nodes in diff --git a/src/bin/blog_server/main.rs b/src/bin/blog_server/main.rs index 6155fff..247290f 100644 --- a/src/bin/blog_server/main.rs +++ b/src/bin/blog_server/main.rs @@ -69,8 +69,12 @@ fn run() -> Result<(), Error> { config.posts_dir.clone() ); - // Dropping the watcher stops its thread, so keep it alive until `main` returns. - let watcher = fs_watcher::start_watching(tx, &config.posts_dir)?; + // Dropping the watcher stops its thread, so keep it alive until the server has stopped. + let watcher = fs_watcher::start_watching( + tx, + &config.posts_dir, + config.fs_event_delay + )?; let renderer_handle = thread::spawn(move || { renderer.handle_events();