task icon indicating copy to clipboard operation
task copied to clipboard

Make watch interval configurable (currently fixed at 5 seconds)

Open gregorriegler opened this issue 1 year ago • 6 comments

I have gradle -t test (this is watching for file-changes and then reruns the tests) and task test --watch open at the same time and task is significantly slower. It reacts to filechanges about a second later, while gradles watcher is instant. Do you see an easy way to make it faster?

gregorriegler avatar Jul 17 '22 22:07 gregorriegler

Can I ask you to provide a minimal reproduction for Gradle and Task so that benchmarks can be made and used for comparison?

ghostsquad avatar Jul 18 '22 03:07 ghostsquad

watch-slow.zip So i made this zip. In the left corner we have Taskfile

version: '3'

tasks:
  test:
    cmds:
      - echo Taskfile
    sources:
      - test.txt

fighting against the oldschooler in the right corner: Makefile with inotifywait

.PHONY: test
test: 
	echo "Makefile";

.PHONY: watch
watch: 
	while true; do \
		make test; \
		inotifywait -qr -e modify -e create -e delete -e move test.txt; \
	done

run both, and change test.txt to trigger the task.

gregorriegler avatar Jul 18 '22 10:07 gregorriegler

Looks like the watch command polls every 5 seconds? https://github.com/go-task/task/blob/master/watch.go#L19 The library being used to poll file system events does not use inotify (as that's not available on all OSs)...

renatoathaydes avatar Jul 18 '22 11:07 renatoathaydes

Hi everybody,

I believe that having an attribute on the Taskfile (and possible a flag, too) to have a different polling interval would do the trick here.

We could also consider switching to a library that uses the OS notification API, but I wanted to avoid it initially because it may behave differently based on the user's OS.

andreynering avatar Aug 04 '22 02:08 andreynering

I use watchexec and just right now. So I'm not waiting for this. But I think it could be beneficial for you to have it built in. Easier setup and scripting for users.

We could also consider switching to a library that uses the OS notification API, but I wanted to avoid it initially because it may behave differently based on the user's OS.

Do you say 'may' because we're not sure? In that case I recommend trying For the thing I'm doing I'm not sure if an interval would be sufficient. But maybe it's worth trying, too

gregorriegler avatar Aug 05 '22 04:08 gregorriegler

I'd like to give it a try.

ilewin avatar Aug 24 '22 06:08 ilewin

This was implemented by @ilewin at #865.

I plan to make a new release still today.

andreynering avatar Oct 14 '22 19:10 andreynering