-
-
Notifications
You must be signed in to change notification settings - Fork 625
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
Task is not getting re-executed after addition/deletion of files when used with --watch argument. #1179
Comments
@PaulisMatrix, I've observed the same behavior as you. I also expected tasks being watched to execute anytime a file matching those tasks' sources' glob pattern would be added, but noticed that they weren't. I took at the code of watch.go and realized this is what is happening:
Looking at the watcher library code, it seems the only way for watcher to generate an event for file creation is by watching the file's containing directory. When a directory is watched, files created and deleted within that directory generate a watcher event. One way for task to match the expectation described in this issue would be to have it also watch the directory in which the task is run. This would generate watcher events for any file creation or deletion. However, even if the sources' glob pattern only matched a few files, watching the entire task directory recursively could potentially put a sizeable burden on the watcher process if the task directory were to contain a large number of files. Also, any file change in the directory, whether the file matched the glob pattern or not, would trigger an event, which would run re-run the task multiple times, potentially unnecessarily. The events would have to be filtered against the glob pattern to only have any actual effect if they matched. This could be more trouble than it's worth. An alternative, which I tried and seems successful, is to make two modifications to the watcher code:
@andreynering, @pd93, what are you thoughts on this? Do you believe that the current behavior, as it stands, is the correct one, or do you believe it should be modified, perhaps with a change similar to my proposal? Here is a quick-and-dirty implementation of the change that seems to work:
|
Hi @radcool! I think that ideally Task should be able to detect new files that matched the glob, yes. Given you worked a little with the code, are you willing to open a PR with this change? |
Is this the approach you want to take or the fsnotify route? The only efficient way to do that on Mac is via cgo IIRC. fsnotify is ok but you can hit inode limits on macOS pretty quickly with it. Mac has a native way of monitoring files that's very efficient however it requires the use of CGO |
@leaanthony We've been avoiding requiring CGO in the codebase, if possible. It seems that fsnotify does not support recursive watch as well. It's in the roadmap since 2024: fsnotify/fsnotify#18. So, it seems that keeping the current polling library is the best route for now. I'm open to suggestions, though. |
Sure thing @andreynering, although I do have a silly question: I'd like to modify Instead, I get:
I haven't written much test in Go and am not familiar with the testing framework. What is the correct procedure I should use to run these unit tests? |
@radcool, do you have any progress on this or do i have to do it from scratch? |
@sirenkovladd, I had written some candidate code, but was stuck at writing the test for it, which is why I posted #1179 (comment). I was waiting for a reply to it before proceeding. |
Could you post the code you have now somewhere? |
@sirenkovladd, the candidate diff I had written is in #1179 (comment). I really was just waiting to have #1179 (comment) answered before I submitted it because I wanted the PR to include a proper test. |
@radcool , re: #1179 (comment), it seems this was fixed in #1567. You should be able to run the tests now. |
Thanks @pbitty. I've written the test and submitted PR #1828. |
Task is not getting re-executed after addition/deletion of files when used with
--watch
argument.Below is the sample taskfile for it.
Works fine without
--watch
arg when the commandtask go-runs
is ran but have to do that manually every time which can be avoided by using--watch
arg but its not working for it as explained above.It seems to be an issue from the watcher pkg itself.
radovskyb/watcher#120
The text was updated successfully, but these errors were encountered: