✨ feat(mq-run): add --watch mode for live query re-execution#1800
Open
harehare wants to merge 2 commits into
Open
✨ feat(mq-run): add --watch mode for live query re-execution#1800harehare wants to merge 2 commits into
harehare wants to merge 2 commits into
Conversation
Add `--watch` flag that monitors input files with `notify` and re-runs the query on each file change. Uses 50ms debounce to coalesce rapid save events.
Contributor
There was a problem hiding this comment.
Pull request overview
Adds an optional --watch flag to the mq CLI (behind a new default-on watch feature) that uses the notify crate to monitor input files and re-run the query on changes, with a 50ms debounce. Conflicts with --stream and requires at least one input file.
Changes:
- New
--watchCLI flag andprocess_watch()method dispatched fromCli::run()for non-streaming execution. - New
watchfeature incrates/mq-run/Cargo.toml(added to defaults) plus an optionalnotifydependency in the workspace. - One integration test for the
--watch/--streamclap conflict and one unit test for the "requires file" error path.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/mq-run/src/cli.rs | Adds watch field, dispatch branch, process_watch() implementation, and unit test. |
| crates/mq-run/tests/integration_tests.rs | Adds integration test asserting --watch --stream fails. |
| crates/mq-run/Cargo.toml | Defines watch feature, adds it to defaults, declares optional notify dep. |
| Cargo.toml | Adds notify = "8.0" workspace dependency. |
| Cargo.lock | Resolves notify 8.2.0 and its transitive deps. |
Comment on lines
+881
to
+895
| let _ = self.process_batch(); | ||
|
|
||
| loop { | ||
| match rx.recv() { | ||
| Ok(Ok(event)) => { | ||
| if matches!( | ||
| event.kind, | ||
| EventKind::Modify(_) | EventKind::Create(_) | ||
| ) { | ||
| // drain pending events to debounce rapid saves | ||
| std::thread::sleep(std::time::Duration::from_millis(50)); | ||
| while rx.try_recv().is_ok() {} | ||
|
|
||
| eprintln!("\n---"); | ||
| let _ = self.process_batch(); |
Comment on lines
+868
to
+896
| for file in files { | ||
| watcher | ||
| .watch(file.as_ref(), RecursiveMode::NonRecursive) | ||
| .into_diagnostic()?; | ||
| } | ||
|
|
||
| let file_list = files | ||
| .iter() | ||
| .map(|f| f.display().to_string()) | ||
| .collect::<Vec<_>>() | ||
| .join(", "); | ||
| eprintln!("Watching {} ... (Ctrl+C to exit)", file_list); | ||
|
|
||
| let _ = self.process_batch(); | ||
|
|
||
| loop { | ||
| match rx.recv() { | ||
| Ok(Ok(event)) => { | ||
| if matches!( | ||
| event.kind, | ||
| EventKind::Modify(_) | EventKind::Create(_) | ||
| ) { | ||
| // drain pending events to debounce rapid saves | ||
| std::thread::sleep(std::time::Duration::from_millis(50)); | ||
| while rx.try_recv().is_ok() {} | ||
|
|
||
| eprintln!("\n---"); | ||
| let _ = self.process_batch(); | ||
| } |
Comment on lines
+855
to
+860
| let Some(files) = &self.files else { | ||
| return Err(miette!("--watch requires at least one input file")); | ||
| }; | ||
| if files.is_empty() { | ||
| return Err(miette!("--watch requires at least one input file")); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add
--watchflag that monitors input files withnotifyand re-runs the query on each file change. Uses 50ms debounce to coalesce rapid save events.