grunt-run icon indicating copy to clipboard operation
grunt-run copied to clipboard

Stopping a task from watch does not seem to work

Open nicojs opened this issue 9 years ago • 2 comments

When you try to stop a task in a watch when which was started before you get the following error:

Running "stop:server" (stop) task
Verifying property stop.server exists in config...ERROR
>> Unable to process task.
Warning: Required config property "stop.server" missing. Use --force to continue.

Aborted due to warnings.

This might be by design because watch starts a new grunt process or something, but i feel like it should work. Example grunt file:

module.exports = function (grunt) {
  require('load-grunt-tasks')(grunt);

  grunt.initConfig({
    watch: {
      ts: {
        files: ['**/*.ts'],
        tasks: ['stop:server', 'build', 'run:server']
      }
    },

    run: {
      server: {
        options: {
          wait: false,
          ready: /.*Listening on port.*/ig
        },
        args: ['./dist/app/index.js'],
      }
    },

    ts: {
      src: {
        tsconfig: true
      }
    }
  });

  grunt.registerTask('build', ['clean', 'ts']);
  grunt.registerTask('serve', ['build', 'run:server', 'watch']);
}

nicojs avatar Feb 05 '16 11:02 nicojs

Yes, this is the case. Ideally grunt-run could use a file-system pid file collection or something, so the active processes are known across processes, but that opens us up to race conditions that I'm not looking to prevent right now. The easiest solution is to tell watch not to spawn a new process: https://github.com/gruntjs/grunt-contrib-watch#why-spawn-as-child-processes-as-a-default

spalger avatar Feb 12 '16 15:02 spalger

Well I tried that (not spawn for watch), the result is that the error is gone now but my express application is running twice now. any hints?

Edit: It might be an application specific issue, for example grunt-express-server has the same issue. Edit2: In my case the reason was, that I had a setInterval function running - this prevented stopping the server cleanly.

neophob avatar Mar 11 '16 22:03 neophob