Skip to content

Commit

Permalink
migrate FileWatcher to separate repo
Browse files Browse the repository at this point in the history
  • Loading branch information
jgraef committed Jul 24, 2024
1 parent a155671 commit 049fd48
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 105 deletions.
3 changes: 3 additions & 0 deletions skunk-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ features = ["trigger"]
#version = "0.1.0"
git = "https://github.com/FeraeLabs/byst.git"

[dependencies.notify-async]
git = "https://github.com/FeraeLabs/notify-async.git"

[dependencies]
axum = { version = "0.7.5", features = ["ws", "macros"] }
chrono = "0.4.38"
Expand Down
26 changes: 14 additions & 12 deletions skunk-cli/src/env/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ use std::{
time::Duration,
};

use notify_async::{
WatchFiles,
WatchModified,
};
use serde::{
de::IntoDeserializer,
Deserialize,
Expand All @@ -21,10 +25,6 @@ use super::{
FileHash,
DEFAULT_CONFIG,
};
use crate::util::watch::{
FileWatcher,
WatchModified,
};

#[derive(Clone, Debug)]
pub struct ConfigFile {
Expand Down Expand Up @@ -125,19 +125,21 @@ fn open(path: &Path) -> Result<Loader, Error> {
toml = Some(DEFAULT_CONFIG.into());
}

let watcher = FileWatcher::new().map_err(|error| {
let watcher = WatchFiles::new().map_err(|error| {
Error::WatchFile {
error,
path: path.to_owned(),
}
})?;

let watch = WatchModified::new(watcher, ConfigFile::DEBOUNCE).map_err(|error| {
Error::WatchFile {
error,
path: path.to_owned(),
}
})?;
let watch = WatchModified::new(watcher)
.map_err(|error| {
Error::WatchFile {
error,
path: path.to_owned(),
}
})?
.with_debounce(ConfigFile::DEBOUNCE);

let toml = if let Some(toml) = toml {
toml
Expand Down Expand Up @@ -184,7 +186,7 @@ struct WatchConfig {

impl WatchConfig {
async fn run(mut self) {
while let Ok(()) = self.watch.wait().await {
while let Ok(()) = self.watch.modified().await {
match self.reload() {
Ok(None) => {}
Ok(Some(_document)) => todo!(),
Expand Down
1 change: 0 additions & 1 deletion skunk-cli/src/util/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
pub mod serve_ui;
pub mod shutdown;
pub mod watch;
4 changes: 2 additions & 2 deletions skunk-cli/src/util/serve_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use axum::{
body::Body,
http::Request,
};
use notify_async::watch_modified;
use skunk_util::trigger;
use tower_http::services::{
ServeDir,
Expand All @@ -28,7 +29,6 @@ use crate::{
Environment,
Error,
},
util::watch::watch_modified,
};

#[derive(Clone, Debug)]
Expand All @@ -44,7 +44,7 @@ impl ServeUi {
let mut watch = watch_modified(path, Duration::from_secs(2))
.expect("Failed to watch for file changes");
tokio::spawn(async move {
while let Ok(()) = watch.wait().await {
while let Ok(()) = watch.modified().await {
tracing::info!("UI modified. Triggering reload");
reload_ui.trigger();
}
Expand Down
90 changes: 0 additions & 90 deletions skunk-cli/src/util/watch.rs

This file was deleted.

0 comments on commit 049fd48

Please sign in to comment.