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 libshire::uuid::Uuid;
|
||||||
use serde::Deserialize;
|
use serde::{Deserialize, Deserializer};
|
||||||
|
|
||||||
#[derive(Deserialize, Clone, Debug)]
|
#[derive(Deserialize, Clone, Debug)]
|
||||||
pub(crate) struct Config {
|
pub(crate) struct Config {
|
||||||
@@ -12,6 +12,8 @@ pub(crate) struct Config {
|
|||||||
pub robots_path: PathBuf,
|
pub robots_path: PathBuf,
|
||||||
pub posts_dir: PathBuf,
|
pub posts_dir: PathBuf,
|
||||||
pub post_media_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 namespace_uuid: Uuid,
|
||||||
pub self_ref: SelfRefConfig,
|
pub self_ref: SelfRefConfig,
|
||||||
pub rss: RssConfig,
|
pub rss: RssConfig,
|
||||||
@@ -44,3 +46,11 @@ impl str::FromStr for Config {
|
|||||||
toml::from_str(s)
|
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(
|
pub(crate) fn start_watching(
|
||||||
tx: mpsc::Sender<DebouncedEvent>,
|
tx: mpsc::Sender<DebouncedEvent>,
|
||||||
watch_path: &Path
|
watch_path: &Path,
|
||||||
|
delay: Duration
|
||||||
) -> Result<RecommendedWatcher, Error>
|
) -> Result<RecommendedWatcher, Error>
|
||||||
{
|
{
|
||||||
let mut watcher = watcher(tx, Duration::from_secs(2))
|
let mut watcher = watcher(tx, delay)
|
||||||
.map_err(Error::CreateWatcher)?;
|
.map_err(Error::CreateWatcher)?;
|
||||||
|
|
||||||
// Watch the path in non-recursive mode, so events are not generated for nodes in
|
// 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()
|
config.posts_dir.clone()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Dropping the watcher stops its thread, so keep it alive until `main` returns.
|
// 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)?;
|
let watcher = fs_watcher::start_watching(
|
||||||
|
tx,
|
||||||
|
&config.posts_dir,
|
||||||
|
config.fs_event_delay
|
||||||
|
)?;
|
||||||
|
|
||||||
let renderer_handle = thread::spawn(move || {
|
let renderer_handle = thread::spawn(move || {
|
||||||
renderer.handle_events();
|
renderer.handle_events();
|
||||||
|
|||||||
Reference in new issue
Block a user