Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Frequently written files may get debounced indefinitely #183

Merged
merged 16 commits into from
Mar 28, 2019

Conversation

sjoshid
Copy link
Contributor

@sjoshid sjoshid commented Mar 5, 2019

This PR is for issue 146. It contains:

  • A new debounced event called OnGoingWrite which is optional by default to keep existing clients unchanged.
  • This event is fired when a file is bombarded with WRITE events.
  • Once the actual WRITE event is fired, this event is unscheduled.

I have made changes for linux and macos platforms. I haven't made for Windows because I don't have access to one. But I'll find a way to get it.

@sjoshid sjoshid changed the title PR for https://github.com/passcod/notify/issues/146 Frequently written files may get debounced indefinitely Mar 5, 2019
@sjoshid
Copy link
Contributor Author

sjoshid commented Mar 6, 2019

@passcod
I was able to implement the Windows version of this. Let me know what you think of this PR or want me to make more changes.
Im looking into the failing test case for Rust 1.26.1 for Mac.

@passcod
Copy link
Member

passcod commented Mar 7, 2019

What's with all the commented out code?

@sjoshid
Copy link
Contributor Author

sjoshid commented Mar 8, 2019

Remnants of my previous attempts to fix this. Cleaned them up.

@sjoshid
Copy link
Contributor Author

sjoshid commented Mar 11, 2019

@passcod
I got rust nightly on macos but the Travis's failing test case poll_watch_file doesn't fail in my local. I also saw that there is another PR with a similar failing test case. Is there anything I need to do fix the failing test case or this is a known problem that can be ignored?

@passcod
Copy link
Member

passcod commented Mar 11, 2019

Yeah, tests are flaky, especially on Travis (likely to do with the virtualisation or something... testing three times per platform tends to help eliminate things out). I usually get them to retry, but I missed that one as I haven't had the time to review this PR in depth last week.

@sjoshid
Copy link
Contributor Author

sjoshid commented Mar 11, 2019

Looks like tests passed. Yaay!! I’m also going to add few more tests cases for the new event depending on your your feedback.

Sent with GitHawk

@sjoshid
Copy link
Contributor Author

sjoshid commented Mar 14, 2019

@passcod Did you get a change to look at this PR? I have another PR that is waiting for this. There is no rust at all. :)

@passcod
Copy link
Member

passcod commented Mar 14, 2019 via email

Copy link
Member

@passcod passcod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General:

  • needs the documentation

src/lib.rs Outdated Show resolved Hide resolved
src/debounce/mod.rs Outdated Show resolved Hide resolved
Copy link
Member

@passcod passcod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Some more general things:

  • The correct spelling of the word is "ongoing", no spaces and no hyphens, so all the methods should be set_ongoing_... and the types should be OngoingWrite, ONGOING_WRITE, etc.

  • This falls under "documentation", but as a note, we should provide some guidance as to what the duration should be, especially in relation to the debounce duration.

  • The method set_ongoing_write_duration is a bit awkward. What that method does is both "switch on the OngoingWrite event, and configure the interval duration" and "re-configure the interval duration" depending on context. The current name implies only the configuring part and it's not obvious that it may be turning on the feature.

  • We provide a way to turn ongoing write events on, but no way to turn them off. That should probably be allowed.

There's several ways to do this, but I think what would be most forward-looking here is adding a new configure(&mut self, option: Config) -> Result<()>; method and making a Config enum that would initially look like:

enum Config {
	OngoingWrites(Option<Duration>),
}

So usage would be like:

watcher.configure(Config::OngoingWrites(Some(Duration::from_ms(50))))?;
watcher.configure(Config::OngoingWrites(None))?;

That takes care of the method name and brings it in line with the other ones (single verbs), and also means that any further runtime options can be added there without more bikeshedding.

Functionally, the trait would contain a default implementation that just returns Ok(()) for everything, and most everything else would keep working the same.

@sjoshid
Copy link
Contributor Author

sjoshid commented Mar 23, 2019

All suggestions are valid and are included. I liked the idea of making is configurable. Made changes accordingly.

Copy link
Member

@passcod passcod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright! That's looking good. I'll merge later today (or tomorrow depending on how life goes).

@@ -611,6 +615,25 @@ pub trait Watcher: Sized {
/// Returns an error in the case that `path` has not been watched or if removing the watch
/// fails.
fn unwatch<P: AsRef<Path>>(&mut self, path: P) -> Result<()>;

/// Configure notify with Configs.
fn configure(&self, option: Config) -> Result<()> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking more about this...should I make this a collection of Config rather than just a Config?

@passcod
Copy link
Member

passcod commented Mar 25, 2019 via email

@sjoshid
Copy link
Contributor Author

sjoshid commented Mar 25, 2019 via email

@passcod passcod merged commit 0a740eb into notify-rs:main Mar 28, 2019
@sjoshid
Copy link
Contributor Author

sjoshid commented Mar 28, 2019

Thanks for merging. 👍

passcod added a commit that referenced this pull request Mar 28, 2019
@passcod passcod added this to the 5.0.0 milestone Mar 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants