exec-limiter-cli
Version:
Run multiple shell commands in parallel, but with a limit.
44 lines (39 loc) • 1.25 kB
JavaScript
var Tilda = require("tilda"),
ExecLimiter = require("exec-limiter"),
readFile = require("read-utf8");
var parser = new Tilda(__dirname + "/../package.json", {
options: [{
name: "max",
opts: ["m", "max"],
desc: "The number of how many parallel processes you want to run.",
required: true,
type: Number
}],
args: [{
name: "input",
desc: "The input file."
}],
examples: ["exec-limiter -m 3 commands.txt"]
}).main(function (action) {
readFile(action.args.input, function (err, content) {
if (err) {
return parser.exit(err);
}
content = content.split("\n").map(function (c) {
return c.trim();
}).filter(function (c) {
return c && !c.startsWith("#");
});
var ex = new ExecLimiter(action.options.max.value);
content.forEach(function (c, index) {
console.log("Scheduling the \"" + c + "\" command.");
ex.add(c, {
stdio: "inherit"
}, function (err, data) {
console.log("Finished task from line " + (index + 1) + " / " + content.length);
});
});
});
});
;