-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
266 additions
and
104 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,21 @@ | ||
|
||
module.exports = function(options) { | ||
return new (require("./lib/manager.js"))(options); | ||
var options = options || {}; | ||
options.timeout = options.timeout || 10000; | ||
options.strategy = options.strategy || "http-servers"; | ||
|
||
if (options.strategy === "http-servers") { | ||
return new (require("./lib/manager-servers.js"))(options); | ||
} | ||
|
||
if (options.strategy === "dedicated-process") { | ||
return new (require("./lib/manager-processes.js"))(options); | ||
} | ||
|
||
throw new Error("Unsupported scripts manager strategy: " + options.strategy); | ||
}; | ||
|
||
module.exports.ScriptManager = require("./lib/manager.js"); | ||
module.exports.ScriptManager = require("./lib/manager-servers.js"); | ||
module.exports.ScriptManagerOnHttpServers = module.exports.ScriptManager; | ||
|
||
module.exports.ScriptManagerOnProcesses = require("./lib/manager-processes.js"); |
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,81 @@ | ||
var childProcess = require("child_process"); | ||
var path = require("path"); | ||
var _ = require("underscore"); | ||
var S = require("string"); | ||
|
||
var ScriptsManager = module.exports = function (options) { | ||
this.options = options; | ||
this.options.timeout = this.options.timeout || 10000; | ||
}; | ||
|
||
|
||
ScriptsManager.prototype.start = function (cb) { | ||
cb(); | ||
}; | ||
|
||
ScriptsManager.prototype.ensureStarted = function (cb) { | ||
cb(); | ||
}; | ||
|
||
ScriptsManager.prototype.execute = function (inputs, options, cb) { | ||
var self = this; | ||
var isDone = false; | ||
|
||
//fix freeze during debugging | ||
process.execArgv = _.filter(process.execArgv, function (arg) { | ||
return !S(arg).startsWith("--debug"); | ||
}); | ||
|
||
process.execArgv.push("--expose-gc"); | ||
|
||
var worker = childProcess.fork(path.join(__dirname, "worker-processes.js")); | ||
|
||
worker.on('message', function (m) { | ||
|
||
|
||
if (m.error) { | ||
isDone = true; | ||
return cb(new Error(m.error)); | ||
} | ||
|
||
if (m.action === "process-response") { | ||
isDone = true; | ||
return cb(null, m.value); | ||
} | ||
|
||
if (m.action === "callback") { | ||
m.params.push(function(){ | ||
var args = Array.prototype.slice.call(arguments); | ||
if (args.length && args[0]) { | ||
args[0] = args[0].message; | ||
} | ||
worker.send({ | ||
action: "callback-response", | ||
params: args | ||
}) | ||
}); | ||
options.callback.apply(self, m.params); | ||
//isDone = true; | ||
//return cb(null, m); | ||
} | ||
}); | ||
|
||
worker.send({ | ||
inputs: inputs, | ||
options: options | ||
}); | ||
|
||
setTimeout(function () { | ||
if (isDone) | ||
return; | ||
|
||
worker.kill(); | ||
|
||
cb(new Error("Timeout error during rendering")); | ||
}, options.timeout || this.options.timeout); | ||
}; | ||
|
||
ScriptsManager.prototype.kill = function () { | ||
}; | ||
|
||
|
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,45 @@ | ||
process.on('uncaughtException', function (err) { | ||
process.send({ | ||
error: err.message, | ||
errorStack: err.stack | ||
}); | ||
|
||
process.exit(); | ||
}); | ||
|
||
var cb; | ||
|
||
function callback() { | ||
cb = arguments[arguments.length - 1]; | ||
var args = Array.prototype.slice.call(arguments); | ||
args.pop(); | ||
process.send({action: "callback", pid: process.pid, params: args.sort()}); | ||
} | ||
|
||
|
||
process.on('message', function (m) { | ||
if (m.action === "callback-response") { | ||
if (m.params.length) { | ||
if (m.params[0]) { | ||
m.params[0] = new Error(m.params[0]); | ||
} | ||
} | ||
cb.apply(this, m.params); | ||
} | ||
|
||
require(m.options.execModulePath)(m.inputs, callback, function (err, val) { | ||
if (err) { | ||
process.send({ | ||
error: err.message, | ||
errorStack: err.stack | ||
}); | ||
} else { | ||
process.send({ | ||
action: "process-response", | ||
value: val | ||
}); | ||
} | ||
|
||
process.exit(); | ||
}); | ||
}); |
File renamed without changes.
Oops, something went wrong.