-
Notifications
You must be signed in to change notification settings - Fork 357
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
Fast changes get lost while tasks are completing #33
Comments
We have an option for this called |
Interrupt seems like an option that still has its use on top of this issue. The behavior described here just seems like changes are being lost/ignored which is probably never the desired result. |
What do you mean by changes are being lost/ignored? Do you have an example? |
You can use this gruntfile to see the issue (with grunt/grunt-contrib-watch installed) module.exports = function(grunt) {
grunt.initConfig({
watch: {
gruntfile: {
files: 'Gruntfile.js',
tasks: ['longtask']
}
}
});
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask('longtask', function(){
var originalGrunt = grunt.file.read('Gruntfile.js');
var done = this.async();
setTimeout(function(){
grunt.file.write('Gruntfile.bak', originalGrunt);
done();
}, 10000);
});
grunt.registerTask('default', 'watch');
}; If you run The expectation would probably be for watch tasks to continue being run for as long as there have been no file changes since the start of the last run. |
Thank you for the example. I still don't understand how the Unless you're suggesting that tasks should be fired off upon every change and not interrupted. If that is the case then I don't agree. Tasks would run all over each other and devour up memory/cpu rather quickly. I think we should just keep the options we have: wait until the task finishes or cancel the previous then start again (using (BTW, technically your example should never fire as the pattern is for |
The example writing to Gruntfile.bak is to showcase how changes could be lost, the changes to Gruntfile.js were still expected to be done externally. This example shows how the task can be kicked off and, if Gruntfile.js is saved again before the task completes, the end result (Gruntfile.bak) is only based off the first changes. The tasks would run in sequence, not immediately, they would just be queued up. In this case, if I save Gruntfile.js 8 times in 10 seconds, it would run twice, once immediately for the first change, once afterward because changes occurred since first start. If interrupt is preferred, then I can work with that, it just seems like a harsh solution that could cause problems for more complex tasks that write files, and the current implementation makes it seem like changes are ignored. This is mostly a problem when several tasks are triggered which can easily make the run time 5-10+ seconds |
Ah my mistake about the example. Firing on a change as well as one more time after, if further changes we're made while the task was running is a not a bad idea. Going to mark this as an |
Implemented in the |
@jsoverson I'll have to take another look at this later. I think it's a good idea unfortunately it causes havoc with setups that watch files that grunt is also editing. It goes into infinite loops. So I reverted it. |
I took a closer look at this, and I think I see the problem. When a file changes during a run, your commit d01491b would rerun all task groups from the current run. That means you would end up rerunning tasks that didn't have any changed files, and those tasks could could change files in other watch groups, leading to the infinite recursion. If you change the logic to only rerun task groups whose files changed during the run, that should fix the infinite recursion. This issue should be reopened, it's still a real bug. |
I don't consider this a bug. It is a feature that isn't a high priority for me to implement. I'm happy to accept a pull request for it though. The problem in the way of this feature is:
It is much safer (and avoids support issues here) to ignore a target while it's running tasks to prevent issues like the above (as the current behavior does). If someone wants to implement this feature, it's going to require a whole lot of tests as the watch behavior is already fairly complex. It also will lead to yet another option for those who want to turn off this behavior. IMO, this behavior isn't worth the effort it will require but I would accept a PR for it with lots of tests. |
Allow me to respectfully disagree about it not being a bug. This project's description is "Run tasks whenever watched files change". And yet here we have files being changed without their tasks being run. If a failure to reliably do that one thing isn't a bug, I don't know what is. To be clear: I'm not asking you to personally make it a priority or to fix it. I just think it should be an open issue for others to see, be aware of, and potentially contribute to. To address the example you gave as a concern: the correct behavior there actually is to repeat forever. That's exactly what the config in the example specifies. And in fact, if you set Hope that makes sense. Happy to discuss further. |
Fair enough, reopening. Thanks! |
Watch tasks are triggered on an initial watch trigger but any changes that occur while the watch tasks are completing get ignored.
Expected :
The text was updated successfully, but these errors were encountered: