fix: improve handling of file and directory events in FlowsMapper#4031
Conversation
Robot Results
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! 🚀 New features to boost your workflow:
|
c8166dc to
4baea86
Compare
4baea86 to
2dc6e36
Compare
2dc6e36 to
4074c63
Compare
I'm not able to observe this when running the I placed the breakpoint at Then I continued until There are |
6abbd13 to
de401c9
Compare
de401c9 to
2c1d75a
Compare
Bravo555
left a comment
There was a problem hiding this comment.
Fixes the problem with reloading scripts, approved
| if matches!(path.extension(), Some("js" | "ts" | "mjs")) { | ||
| self.processor.remove_script(path).await; | ||
| self.send_updated_subscriptions().await?; | ||
| self.update_flow_status(path).await?; | ||
| } else if path.extension() == Some("toml") { | ||
| self.processor.remove_flow(path).await; | ||
| self.send_updated_subscriptions().await?; | ||
| self.update_flow_status(path).await?; | ||
| } |
There was a problem hiding this comment.
if matches!(path.extension(), Some("js" | "ts" | "mjs")) {
self.processor.remove_script(path).await;
} else if path.extension() == Some("toml") {
self.processor.remove_flow(path).await;
}
self.send_updated_subscriptions().await?;
self.update_flow_status(path).await?;
There was a problem hiding this comment.
I guess that assumes that we don't get any other notifications which are from .js, .ts, .mjs nor .toml files?
There was a problem hiding this comment.
You are correct, we have to handle the case of a flows unrelated file.
There was a problem hiding this comment.
I pushed the recommended change
Signed-off-by: reubenmiller <reuben.d.miller@gmail.com>
…ning Signed-off-by: reubenmiller <reuben.d.miller@gmail.com>
Signed-off-by: Marcel Guzik <marcel.guzik@cumulocity.com>
2c1d75a to
a016b7b
Compare
Proposed changes
Fixes flow being permanently lost from memory after a package manager updates it (deletes then recreates the files), even though files are restored on disk (#4023).
Three targeted fixes:
1.
remove_script()— unload instead of remove (registry.rs)When a script file is deleted, flows referencing it are now unloaded (moved to
unloaded_flows) instead of being silently ignored with a warning. This means when the script is restored andreload_script()callsdrain_unloaded(), the flow is rediscovered and reloaded automatically.Previously,
remove_script()only logged a warning and returned early — the flow stayed in theflowsmap with a broken script reference but was never re-evaluated when the script came back.2.
add_flow()— no-op on missing file instead of destructive removal (registry.rs)Changed from
if tokio::fs::read_to_string().is_err() → remove_flow()toif !path.is_file() → return.The old code would destroy a valid in-memory flow on a transient read failure (e.g. file briefly absent during a package update). The new code simply returns — if the file was truly deleted, a
FileDeletedevent will handle removal; if it's being replaced, a subsequentModifiedevent will reload it.3.
on_file_removed()— skip staleFileDeletedevents (actor.rs)Added a
path.exists()guard at the top ofon_file_removed(). During a package update,FileDeletedevents can arrive after the file has already been re-created. Without this guard, the stale event would remove the freshly-reloaded flow.Also added the missing
send_updated_subscriptions()+update_flow_status()calls for script removals, which were previously only done for.tomlremovals.Types of changes
Paste Link to the issue
#4023
Checklist
just prepare-devonce)just formatas mentioned in CODING_GUIDELINESjust checkas mentioned in CODING_GUIDELINESFurther comments