Coder Social home page Coder Social logo

Delay for triggering about filewatcher HOT 24 CLOSED

AlexWayfer avatar AlexWayfer commented on September 26, 2024
Delay for triggering

from filewatcher.

Comments (24)

thomasfl avatar thomasfl commented on September 26, 2024 2

Yes, let's do it!

from filewatcher.

thomasfl avatar thomasfl commented on September 26, 2024 1

👍

I think the best way to tackle this is to do what a similar js cli tool called watch does:

    --wait=<seconds>
        Duration, in seconds, that watching will be disabled
        after running <command>. Setting this option will
        throttle calls to <command> for the specified duration.

https://github.com/mikeal/watch

@gisikw You've been engaged in the same problem recently. Any comments?

If we add a --wait option then the --dontwait option should probably be renamed to --immediate to avoid confusion.

from filewatcher.

AlexWayfer avatar AlexWayfer commented on September 26, 2024 1

I support this decision!

from filewatcher.

AlexWayfer avatar AlexWayfer commented on September 26, 2024 1

@thomasfl I'd like to decide about the variables, maybe they need some changes with new behavior.

And today I thought of a slightly better scheme of work for --delay option, I'll create a new PR.

from filewatcher.

AlexWayfer avatar AlexWayfer commented on September 26, 2024

I'm looking at code… and I think that possible we don't need for wait option.

In Filewatcher#filesystem_updated? we're getting array of changes. And just run command (block) for each of these.

Maybe… ignore all changes except the first one? Or pass all changes (filename + event) as array… but should we run command many times for it?

I don't know…

from filewatcher.

thomasfl avatar thomasfl commented on September 26, 2024

Good idea @AlexWayfer! That's the simplest thing that could possible work, and probably also the solution that causes less surprises for the users.

If one file system scan finds more than one change, then just ignore all changes except the first one. Passing all changes as an array, can make sense if event is set to multiple_updates.

from filewatcher.

gisikw avatar gisikw commented on September 26, 2024

If this change is going to be made, could it be behind a flag? Some use cases (like compiling-on-save) could be broken if only the first detected file is processed.

from filewatcher.

AlexWayfer avatar AlexWayfer commented on September 26, 2024

@gisikw Of course! Options are good 😅

But I don't know what default is better 🤔

Any thoughts, @thomasfl?

from filewatcher.

thomasfl avatar thomasfl commented on September 26, 2024

Agree with Kevin. The least surprising behaviour would probably be to have an option for only returning the first file if several changes have occured in one file system scan.

I don't have a good name for this option. Maybe --groupChanges / :groupChanges, since it makes several file system changes appear as a single event.

I did like the idea of returning a list of changed files.

from filewatcher.

AlexWayfer avatar AlexWayfer commented on September 26, 2024

@thomasfl Maybe --each? Or --every? But without short version, I guess, or -E.

Or --batch (-b).

from filewatcher.

thomasfl avatar thomasfl commented on September 26, 2024

Consider adding a --debounce action where users can specify the time in milleseconds without any changes before an event is triggered.

@gisikw @AlexWayfer

from filewatcher.

AlexWayfer avatar AlexWayfer commented on September 26, 2024

@thomasfl Why? I answered you here. No need for --wait, --delay or --debounce option. Just one command execution for many changed files once.

from filewatcher.

thomasfl avatar thomasfl commented on September 26, 2024

When many file changes happens, how do you know that all of the file changes is done? The debounce option specifies how long to wait before filewatcher knows that all changes are really finished. Just an idea.

from filewatcher.

AlexWayfer avatar AlexWayfer commented on September 26, 2024

Maybe just increase --interval? But you'll get less real-time command spawn, yes.

OK, this makes sense.

from filewatcher.

gisikw avatar gisikw commented on September 26, 2024

FWIW, I think a --debounce option makes sense. Rolling things up into a single dispatch with multiple filenames also seems to resolve the issue, and the PR looks great.

That said, I think dispatching only the first $FILENAME is potentially misleading, and I know I could quite easily forget the -E flag, giving me a false sense that I was processing a complete set of files. Would much prefer this as an opt-in batching feature (or perhaps even don't yield $FILENAME, but a \n-delineated xargs-able list or something? Just to distinguish it from the standard behavior?)

@thomasfl To your point, I think @AlexWayfer's fix works just like your proposed debounce, provided that you also avail yourself of --interval?

from filewatcher.

AlexWayfer avatar AlexWayfer commented on September 26, 2024

I can make another PR with option, but I think --delay is better name than --debounce: we talk about delay between two command executes, that is greater than --interval, as I understood.

@gisikw I agree with multiple filenames in env variable, but what is better when -E is setted: $FILENAME with \nor $FILENAMES? The same about $EVENT, $BASENAME and others.

from filewatcher.

gisikw avatar gisikw commented on September 26, 2024

Yeah, I'd argue for pluralizing the variables. Just nervous that shipping a new version of the tool, such that old CLI commands that were valid in prior versions don't explicitly break, but do fail to run on all files, makes me nervous for anybody who may not watch the changelog.

Pluralizing the vars would at least make sure that legacy syntax would fail (speaking for myself, I've got a bunch of tmuxinator projects with filewatcher commands hard-coded, so a same-syntax, different-behavior change could catch me flat-footed)

from filewatcher.

AlexWayfer avatar AlexWayfer commented on September 26, 2024

@gisikw Breaking changes must be shipped with new version, and dependencies must be locked.

I'll improve env variables in #53.

from filewatcher.

thomasfl avatar thomasfl commented on September 26, 2024

@gisikw Maybe this is bullshit, but what if both environments variables $FILENAME and $FILENAMES was exported? $FILENAME could be the first filename in the $FILENAMES list. Just to make the filewatcher CLI backwards compatible?

from filewatcher.

AlexWayfer avatar AlexWayfer commented on September 26, 2024

I've added --delay option in separate commit of #53 (now here).

Waiting for the decision about env variables.

from filewatcher.

gisikw avatar gisikw commented on September 26, 2024

@thomasfl I would argue that you want it to break. Particularly since this is often used as a CLI tool, and people might not pay close attention to the version number if they add it on a new machine. My concern here is that the change would create a silent "failure", for example:

filewatcher '**/*.coffee' 'coffee -c $FILENAME'
# in another shell...
git checkout branch-with-a-few-changes

With the existing (and older) versions of filewatcher, this works as expected, and each file would get recompiled. But the PR changes the default behavior, and now only one of them gets compiled. It's a silent failure that the user isn't clued into, and they'd only encounter the need to change their scripts to use the -E flag if they just-so-happen to catch what's wrong under the right use case.

If the default behavior is going to change, then I think it's best to make things backward incompatible, because the same syntax now means something different, and you want to give users a very loud warning that they command might not being doing what they expect it to do.

That said, @AlexWayfer's --delay option would preserve the original behavior, it looks like, since the delay is default-off, which avoids the whole issue. Just my thoughts!

from filewatcher.

thomasfl avatar thomasfl commented on September 26, 2024

@gisikw Thanks for your feedback.

@AlexWayfer I have approved your pull request. Thank you very much for your effort.

I will need to test out the CLI before pushing it to rubygems. It can take a few days. I've been busy lately both at work and at home.

from filewatcher.

thomasfl avatar thomasfl commented on September 26, 2024

@AlexWayfer Good. Looking forward to seeing the new PR.

from filewatcher.

AlexWayfer avatar AlexWayfer commented on September 26, 2024

@thomasfl You merged it: #54

Maybe a new PR will be for the env variables after the final decision.

from filewatcher.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.