mirror of
https://github.com/watchexec/watchexec.git
synced 2024-09-28 22:21:33 +02:00
Use Durations for durations in Config
This commit is contained in:
parent
75ef0095ff
commit
15cdd7c754
@ -3,6 +3,7 @@ use log::LevelFilter;
|
||||
use std::{
|
||||
ffi::OsString,
|
||||
path::{PathBuf, MAIN_SEPARATOR},
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use crate::config::{Config, ConfigBuilder};
|
||||
@ -205,11 +206,11 @@ where
|
||||
builder.ignores(ignores);
|
||||
|
||||
if args.occurrences_of("poll") > 0 {
|
||||
builder.poll_interval(value_t!(args.value_of("poll"), u32).unwrap_or_else(|e| e.exit()));
|
||||
builder.poll_interval(Duration::from_millis(value_t!(args.value_of("poll"), u64).unwrap_or_else(|e| e.exit())));
|
||||
}
|
||||
|
||||
if args.occurrences_of("debounce") > 0 {
|
||||
builder.debounce(value_t!(args.value_of("debounce"), u64).unwrap_or_else(|e| e.exit()));
|
||||
builder.debounce(Duration::from_millis(value_t!(args.value_of("debounce"), u64).unwrap_or_else(|e| e.exit())));
|
||||
}
|
||||
|
||||
builder.on_busy_update(if args.is_present("restart") {
|
||||
|
@ -13,7 +13,7 @@
|
||||
//! .expect("mission failed");
|
||||
//! ```
|
||||
|
||||
use std::path::PathBuf;
|
||||
use std::{time::Duration, path::PathBuf};
|
||||
|
||||
use crate::process::Shell;
|
||||
use crate::run::OnBusyUpdate;
|
||||
@ -43,9 +43,9 @@ pub struct Config {
|
||||
/// Specify what to do when receiving updates while the command is running.
|
||||
#[builder(default)]
|
||||
pub on_busy_update: OnBusyUpdate,
|
||||
/// Interval to debounce the changes. (milliseconds)
|
||||
#[builder(default = "500")]
|
||||
pub debounce: u64,
|
||||
/// Interval to debounce the changes.
|
||||
#[builder(default = "Duration::from_millis(500)")]
|
||||
pub debounce: Duration,
|
||||
/// Run the commands right after starting.
|
||||
#[builder(default = "true")]
|
||||
pub run_initially: bool,
|
||||
@ -72,9 +72,9 @@ pub struct Config {
|
||||
/// Force using the polling backend.
|
||||
#[builder(default)]
|
||||
pub poll: bool,
|
||||
/// Interval for polling. (milliseconds)
|
||||
#[builder(default = "1000")]
|
||||
pub poll_interval: u32,
|
||||
/// Interval for polling.
|
||||
#[builder(default = "Duration::from_secs(1)")]
|
||||
pub poll_interval: Duration,
|
||||
}
|
||||
|
||||
impl ConfigBuilder {
|
||||
|
@ -131,7 +131,7 @@ where
|
||||
})?;
|
||||
|
||||
if watcher.is_polling() {
|
||||
warn!("Polling for changes every {} ms", args.poll_interval);
|
||||
warn!("Polling for changes every {:?} ms", args.poll_interval);
|
||||
}
|
||||
|
||||
// Call handler initially, if necessary
|
||||
@ -278,7 +278,7 @@ pub fn run(args: Config) -> Result<()> {
|
||||
fn wait_fs(
|
||||
rx: &Receiver<Event>,
|
||||
filter: &NotificationFilter,
|
||||
debounce: u64,
|
||||
debounce: Duration,
|
||||
no_meta: bool,
|
||||
) -> Vec<PathOp> {
|
||||
let mut paths = Vec::new();
|
||||
@ -310,8 +310,7 @@ fn wait_fs(
|
||||
}
|
||||
|
||||
// Wait for filesystem activity to cool off
|
||||
let timeout = Duration::from_millis(debounce);
|
||||
while let Ok(e) = rx.recv_timeout(timeout) {
|
||||
while let Ok(e) = rx.recv_timeout(debounce) {
|
||||
if let Some(ref path) = e.path {
|
||||
let pathop = PathOp::new(path, e.op.ok(), e.cookie);
|
||||
if cache.contains_key(&pathop) {
|
||||
|
@ -1,4 +1,6 @@
|
||||
use notify::{raw_watcher, PollWatcher, RecommendedWatcher, RecursiveMode};
|
||||
use std::convert::TryFrom;
|
||||
use std::time::Duration;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::mpsc::Sender;
|
||||
|
||||
@ -25,12 +27,12 @@ impl Watcher {
|
||||
tx: Sender<Event>,
|
||||
paths: &[PathBuf],
|
||||
poll: bool,
|
||||
interval_ms: u32,
|
||||
interval: Duration,
|
||||
) -> Result<Self, Error> {
|
||||
use notify::Watcher;
|
||||
|
||||
let imp = if poll {
|
||||
let mut watcher = PollWatcher::with_delay_ms(tx, interval_ms)?;
|
||||
let mut watcher = PollWatcher::with_delay_ms(tx, u32::try_from(interval.as_millis()).unwrap_or(u32::MAX))?;
|
||||
for path in paths {
|
||||
watcher.watch(path, RecursiveMode::Recursive)?;
|
||||
debug!("Watching {:?}", path);
|
||||
|
Loading…
Reference in New Issue
Block a user