This repository has been archived by the owner on Mar 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add --setup feature, enhance tracker ps killing.
Fixes #51 * Add --setup feature for task over lifetime of actions. * Abort actions with error if setup fails. * Move tracker to separate file. * Have tracker kill entire process tree of tasks. * Wait on tracker to kill everything before finishing tasks. * Add convenience helper functions.
- Loading branch information
1 parent
60cba15
commit c250c0f
Showing
7 changed files
with
196 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
"use strict"; | ||
|
||
var async = require("async"); | ||
var treeKill = require("tree-kill"); | ||
|
||
/** | ||
* Multi-process tracker. | ||
* | ||
* @returns {void} | ||
*/ | ||
var Tracker = module.exports = function Tracker() { | ||
this.procs = []; | ||
}; | ||
|
||
/** | ||
* Add process and track close. | ||
* | ||
* @param {Object} proc Child process object | ||
* @returns {Object} Child process object | ||
*/ | ||
Tracker.prototype.add = function (proc) { | ||
if (!proc) { return proc; } | ||
|
||
var self = this; | ||
|
||
// Track. | ||
self.procs.push(proc); | ||
|
||
// Remove from tracked list when closed. | ||
proc.on("close", function () { | ||
self.procs = self.procs.filter(function (obj) { | ||
return obj.pid !== proc.pid; | ||
}); | ||
}); | ||
|
||
return proc; | ||
}; | ||
|
||
/** | ||
* Terminate all open processes | ||
* | ||
* @param {Function} callback Called when kills are issued | ||
* @returns {void} | ||
*/ | ||
Tracker.prototype.kill = function (callback) { | ||
if (this.procs.length === 0) { return callback(); } | ||
|
||
async.map(this.procs, function (proc, cb) { | ||
// Ignore errors: We want to kill as many procs as we can. | ||
treeKill(proc.pid, "SIGTERM", function () { cb(); }); | ||
}, callback); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.