Skip to content

Commit bcbb61e

Browse files
committed
Fix flow reloading on inotify events
The flow actor was trying to be smart, but actually too smart. It was reloading a flow on an modified event only if the file was actually loading. However, inotify might wrongly notify an update for a new file. Signed-off-by: Didier Wenzek <didier.wenzek@free.fr>
1 parent 1c4d7a5 commit bcbb61e

File tree

2 files changed

+4
-11
lines changed

2 files changed

+4
-11
lines changed

crates/extensions/tedge_flows/src/actor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl Actor for FlowsMapper {
7373
if matches!(path.extension(), Some("js" | "ts" | "mjs")) {
7474
self.processor.reload_script(path).await;
7575
} else if path.extension() == Some("toml") {
76-
self.processor.reload_flow(path).await;
76+
self.processor.add_flow(path).await;
7777
self.send_updated_subscriptions().await?;
7878
}
7979
}

crates/extensions/tedge_flows/src/runtime.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -249,22 +249,15 @@ impl MessageProcessor {
249249

250250
pub async fn add_flow(&mut self, path: Utf8PathBuf) {
251251
let flow_id = Self::flow_id(&path);
252-
if !self.flows.contains_key(&flow_id) && self.load_flow(flow_id, path.clone()).await {
253-
info!(target: "flows", "Loaded new flow {path}");
254-
}
255-
}
256-
257-
pub async fn reload_flow(&mut self, path: Utf8PathBuf) {
258-
let flow_id = Self::flow_id(&path);
259-
if self.flows.contains_key(&flow_id) && self.load_flow(flow_id, path.clone()).await {
260-
info!(target: "flows", "Reloaded updated flow {path}");
252+
if self.load_flow(flow_id, path.clone()).await {
253+
info!(target: "flows", "Loading flow {path}");
261254
}
262255
}
263256

264257
pub async fn remove_flow(&mut self, path: Utf8PathBuf) {
265258
let flow_id = Self::flow_id(&path);
266259
self.flows.remove(&flow_id);
267-
info!(target: "flows", "Removed deleted flow {path}");
260+
info!(target: "flows", "Removing flow {path}");
268261
}
269262
}
270263

0 commit comments

Comments
 (0)