Configurable file system event delay
This commit is contained in:
1 parent
3c5965dd5d
commit
25bfcde703
3 files changed
+21
-6
No files matched your search
@@ -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<Duration, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>
|
||||
{
|
||||
u64::deserialize(deserializer)
|
||||
.map(Duration::from_millis)
|
||||
}
|
||||
@@ -17,10 +17,11 @@ use crate::Error;
|
||||
|
||||
pub(crate) fn start_watching(
|
||||
tx: mpsc::Sender<DebouncedEvent>,
|
||||
watch_path: &Path
|
||||
watch_path: &Path,
|
||||
delay: Duration
|
||||
) -> Result<RecommendedWatcher, Error>
|
||||
{
|
||||
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
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in new issue
Block a user