Comments (24)
Yes, let's do it!
from filewatcher.
👍
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.
I support this decision!
from filewatcher.
@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.
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.
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.
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.
@gisikw Of course! Options are good 😅
But I don't know what default is better 🤔
Any thoughts, @thomasfl?
from filewatcher.
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.
@thomasfl Maybe --each
? Or --every
? But without short version, I guess, or -E
.
Or --batch
(-b
).
from filewatcher.
Consider adding a --debounce action where users can specify the time in milleseconds without any changes before an event is triggered.
from filewatcher.
@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.
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.
Maybe just increase --interval
? But you'll get less real-time command spawn, yes.
OK, this makes sense.
from filewatcher.
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.
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 \n
or $FILENAMES
? The same about $EVENT
, $BASENAME
and others.
from filewatcher.
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.
@gisikw Breaking changes must be shipped with new version, and dependencies must be locked.
I'll improve env variables in #53.
from filewatcher.
@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.
I've added --delay
option in separate commit of #53 (now here).
Waiting for the decision about env variables.
from filewatcher.
@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.
@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.
@AlexWayfer Good. Looking forward to seeing the new PR.
from filewatcher.
Maybe a new PR will be for the env variables after the final decision.
from filewatcher.
Related Issues (20)
- The filewatch does not work if files are creating too fast HOT 5
- unexpected behavior on Windows and two callbacks on one DELETE on Linux HOT 3
- --restart flag support process kill with custom signal? HOT 3
- filewatcher loops infinitely when executing a script that invokes ssh HOT 9
- "Batching" all changes into one event HOT 3
- Sync to database example HOT 1
- Question regarding API HOT 3
- How do I know which directory has changed when there is a change HOT 1
- Stable release soon? HOT 2
- Filewatcher not found in Ruby 3.2.2 HOT 13
- When used with multiple watch paths block vars are improperly assigned HOT 5
- Speed up tests HOT 1
- `Filewatcher` vs `FileWatcher` case change from rubygems HOT 4
- 1.0 Release -- event 'updated' raises NotImplementedError HOT 4
- Crash on file deletion (via executable) HOT 1
- Doesn't seem to work if repos have a dot in the name HOT 2
- Replace Gemnasium with Depfu
- Trollop dependency is deprecated HOT 9
- Switch from Travis CI to Cirrus CI HOT 1
- Detect rename HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from filewatcher.