gulp - How to get process.kill run when restarting due to changes -
i want use gulp run task, alway restart change, fail test.js listen port of 9001 when restarting, port used. want focus on restart event , kill listen event, right way? here code:
gulp.task('report', ['clean-build-app-dev', 'validate-devserver-scripts'], function(){ plugins.nodemon({ script: 'server/server.js', ext: 'js', args:['--ignore', 'test/'], env: { node_env: 'development' } }) .on('start', function () { plugins.nodemon({ script: 'test/phantomflow/test/test.js', args:['--delay', '2.5', '--ignore', 'test/'], stdout: false }) .on('readable', function() { this.stdout.on('data', function(chunk) { if (/completed /.test(chunk)) { // plugins.nodemon({ script: 'test/phantomflow/test/test.js', args:['report', '--delay', '2', '--ignore', 'test/'] }); // run twice, use exec instand, know how solve it? const { exec } = require('child_process'); exec('node test/phantomflow/test/test.js report', ['--delay', '2', '--ignore', 'test/']); } process.stdout.write(chunk); }); this.stderr.pipe(process.stderr); }) .on('restart', function() { console.log('* sigusr2 detected_________11111111111111___________________'); // process.once('sigusr2', function () { // // gracefulshutdown(function () { // // process.kill(process.pid, 'sigusr2'); // // }); // }); process.once('sigusr2', function(code) { console.log('* sigusr2 detected_____________22222222222222222_______________'); process.kill(process.pid, 'sigusr2'); }); }); }); });
the error below:
[17:07:45] [nodemon] restarting due changes... * sigusr2 detected_________11111111111111___________________ [17:07:45] [nodemon] starting `node test/phantomflow/test/test.js --delay 2.5 --ignore test/` parallelising 1 test files on 1 processes. picking job: flows\carepilotweb.test.js events.js:160 throw er; // unhandled 'error' event ^ error: listen eaddrinuse :::9001 @ object.exports._errnoexception (util.js:1026:11) @ exports._exceptionwithhostport (util.js:1049:20) @ server._listen2 (net.js:1257:14) @ listen (net.js:1293:10) @ server.listen (net.js:1389:5) @ function.app.listen (c:\workspace\deleteme_0420\carepilot-web\test\phantomflow\node_modules\connect\lib\proto.js:232:24) @ object.<anonymous> (c:\workspace\deleteme_0420\carepilot-web\test\phantomflow\test\test.js:46:4) @ module._compile (module.js:570:32) @ object.module._extensions..js (module.js:579:10) @ module.load (module.js:487:32) [17:07:46] [nodemon] app crashed - waiting file changes before starting...
how log changed file name? or can anyway prevent watch / restart? sometime may restart in loop without stopping when there no change. how solve it, can give me suggestion, thanks.
edit: when change task file this, work:
gulp.task('report-debug', /*['clean-build-app-dev', 'validate-devserver-scripts'],*/ function(){ // start nodemon load test.js plugins.nodemon({ script: 'server/server.js', ext: 'js', watch: ['server/'], args:['--ignore', 'test/'], env: { node_env: 'development' } }) .on('start', function () { plugins.nodemon({ script: 'test/phantomflow/test/test.js', watch: ['server/'], args:['debug', '--ignore', 'test/'], stdout: false }) .on('readable', function() { this.stdout.on('data', function(chunk) { if (/completed /.test(chunk)) { const { exec } = require('child_process'); exec('node test/phantomflow/test/test.js report', ['--ignore', 'test/']); } process.stdout.write(chunk); }); this.stderr.pipe(process.stderr); }); }); });
this kind code works too:
gulp.task('report', ['clean-build-app-dev', 'validate-devserver-scripts'], function(){ // start nodemon load test.js var ls, innerls; plugins.nodemon({ script: 'server/server.js', ext: 'js', args:['--ignore', 'test/', '--ignore', 'gulpfile.js'], env: { node_env: 'development' } }) .on('start', function () { const { spawn } = require('child_process'); ls = spawn('node', ['test/phantomflow/test/test.js']); ls.stdout.on('data', (data) => { if (/completed /.test(data)) { // const { exec } = require('child_process'); // exec('node test/phantomflow/test/test.js report', ['--delay', '2', '--ignore', 'test/']); innerls = spawn('node', ['test/phantomflow/test/test.js', 'report']); } process.stdout.write(data); }); ls.stderr.on('data', (data) => { console.log(`stderr: ${data}`); }); ls.on('close', (code) => { console.log(`child process exited code ${code}`); }); }) .on('restart', function() { if(ls) ls.kill('sigint'); if(innerls) innerls.kill('sigint'); }); });
Comments
Post a Comment