Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
forever – load return undefined
/*jslint white: true, devel: true, debug: true, onevar: true,
node: true, undef: true, nomen: true, regexp: false,
plusplus: false, bitwise: true, unparam: false, es5: true,
newcap: true, on: true, strict: true */
(function (global, undefined) {
"use strict";
//get the forever module
var forever = require("forever"),
rootPath = process.cwd(),
emitter = rootPath + "/emitter.js",
outputList = function () {
console.log("= Output forever list:");
var list = (forever.list(false) || []),
open = 0;
for (var i=0,il=list.length; i<il; i++) {
if (list[i].dead !== true) {
open++;
}
}
console.log("= Number of open processors: ", open);
console.log("= ", forever.list(true));
console.log("");
};
//Load data
console.log("> Test begin:");
forever.load({
root : rootPath + "/log/",
pidPath : rootPath + "/.forever/"
}).on("load", function () {
console.log("");
console.log("# load fire");
//Output list
outputList();
//Clean up
console.log("> clean up");
forever.cleanUp().on("cleanUp", function () {
//log fire message
console.log("");
console.log("# cleanUp fire");
//Output list
outputList();
//Start emmiter.js
console.log("> start emitter.js");
forever.start(emitter, {
forever: false,
"outFile" : rootPath + "/log/emitter_output.log",
"errFile" : rootPath + "/log/emitter_error.log"
}).on("exit", function () {
//log fire message
console.log("");
console.log("# exit fire");
outputList();
}).on("start", function () {
//log fire message
console.log("");
console.log("# start fire");
//Output list
outputList();
//Stop all processors
console.log("");
console.log("> stop all processors");
forever.stopAll(false).on("stopAll", function () {
console.log("# stopAll fire");
//Output list
outputList();
});
});
});
});
})(global);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.