Skip to content

Commit

Permalink
use config_error flag and content event for notify
Browse files Browse the repository at this point in the history
Signed-off-by: Sahil Yeole <[email protected]>
  • Loading branch information
beelchester committed Aug 15, 2024
1 parent b5c0107 commit 085009a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
6 changes: 2 additions & 4 deletions src/cli/server/http_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,14 @@ impl Server {
if let Some(receiver) = rec {

Check warning on line 59 in src/cli/server/http_server.rs

View check run for this annotation

Codecov / codecov/patch

src/cli/server/http_server.rs#L59

Added line #L59 was not covered by tests
tokio::select! {
_ = receiver.recv() => {
tracing::info!("Server shutdown signal received");
runtime.shutdown_background();
tracing::info!("Server shutdown complete");
}
_ = handle => {
tracing::info!("Server completed without shutdown signal");
tracing::debug!("Server completed without shutdown signal");
}
}
} else {
handle.await?;
let _ = handle.await?;

Check warning on line 69 in src/cli/server/http_server.rs

View check run for this annotation

Codecov / codecov/patch

src/cli/server/http_server.rs#L69

Added line #L69 was not covered by tests
}
Ok(())

Check warning on line 71 in src/cli/server/http_server.rs

View check run for this annotation

Codecov / codecov/patch

src/cli/server/http_server.rs#L71

Added line #L71 was not covered by tests
}
Expand Down
20 changes: 11 additions & 9 deletions src/cli/tc/start.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use std::sync::Arc;

use anyhow::{Context, Result};
use notify::{Config, RecommendedWatcher, RecursiveMode, Watcher};
use std::sync::Arc;
use tokio::sync::{broadcast, Mutex};
use tokio::sync::broadcast;
use tokio::task;

use super::helpers::log_endpoint_set;
Expand Down Expand Up @@ -57,12 +58,12 @@ async fn start_watch_server(
}

loop {
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
match watch_rx.recv() {
Ok(event) => {
if let Ok(event) = event {
if let notify::EventKind::Modify(notify::event::ModifyKind::Data(_)) =
event.kind
if let notify::EventKind::Modify(notify::event::ModifyKind::Data(
notify::event::DataChange::Content,
)) = event.kind

Check warning on line 66 in src/cli/tc/start.rs

View check run for this annotation

Codecov / codecov/patch

src/cli/tc/start.rs#L61-L66

Added lines #L61 - L66 were not covered by tests
{
tracing::info!("File change detected");
if let Err(err) = tx.send(()) {
Expand All @@ -73,6 +74,7 @@ async fn start_watch_server(
}
Err(e) => tracing::error!("Watch error: {:?}", e),

Check warning on line 75 in src/cli/tc/start.rs

View check run for this annotation

Codecov / codecov/patch

src/cli/tc/start.rs#L75

Added line #L75 was not covered by tests
}
tokio::time::sleep(tokio::time::Duration::from_millis(500)).await;

Check warning on line 77 in src/cli/tc/start.rs

View check run for this annotation

Codecov / codecov/patch

src/cli/tc/start.rs#L77

Added line #L77 was not covered by tests
}
});

Expand All @@ -81,7 +83,7 @@ async fn start_watch_server(
let file_paths = file_paths.clone();
async move {
let mut rec = Some(&mut rx);
let shown_warning = Arc::new(Mutex::new(false));
let mut config_error = false;

Check warning on line 86 in src/cli/tc/start.rs

View check run for this annotation

Codecov / codecov/patch

src/cli/tc/start.rs#L79-L86

Added lines #L79 - L86 were not covered by tests
loop {
match config_reader.read_all(&file_paths).await {
Ok(config_module) => {
Expand All @@ -91,14 +93,14 @@ async fn start_watch_server(
if let Err(err) = server.fork_start(rec.as_deref_mut()).await {
tracing::error!("Failed to start server: {}", err);
}
*shown_warning.lock().await = false;
config_error = false;
tracing::info!("Restarting server");

Check warning on line 97 in src/cli/tc/start.rs

View check run for this annotation

Codecov / codecov/patch

src/cli/tc/start.rs#L88-L97

Added lines #L88 - L97 were not covered by tests
}
Err(err) => {
if !*shown_warning.lock().await {
if !config_error {
tracing::error!("Failed to read config files: {}", err);
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
*shown_warning.lock().await = true;
config_error = true;
}

Check warning on line 104 in src/cli/tc/start.rs

View check run for this annotation

Codecov / codecov/patch

src/cli/tc/start.rs#L99-L104

Added lines #L99 - L104 were not covered by tests
}
}
Expand Down

0 comments on commit 085009a

Please sign in to comment.