Skip to content

Commit

Permalink
Implement config file loading.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kami committed Nov 26, 2011
1 parent c428ff8 commit d813c25
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions lib/process_runner/runner.js
Expand Up @@ -47,12 +47,18 @@ var DEFAULT_TIMEOUT = 10 * 1000;
var SOCKET_CONNECT_TIMEOUT = 2000;
var SOCKET_CONNECT_INTERVAL = 1000;

function ProcessRunner(config) {
this._config = this.verifyConfig(config);
function ProcessRunner(configPath) {
this._config = this.verifyConfig(this._readConfigFile(configPath));
this._processes = [];
}


ProcessRunner.prototype._readConfigFile = function(filePath) {
var config = JSON.parse(fs.readFileSync(filePath));
return config;
};


/**
* Inspect the config, make sure all the options are valid and return a cleaned
* config object.
Expand All @@ -64,9 +70,9 @@ ProcessRunner.prototype.verifyConfig = function(config) {
cleaned = {};

// Verify that all the specified dependencies are defined
for (key in this._config) {
if (this._config.hasOwnProperty(key)) {
value = this._config[key];
for (key in config) {
if (config.hasOwnProperty(key)) {
value = config[key];
available[key] = true;

if (!value.cmd) {
Expand All @@ -80,8 +86,8 @@ ProcessRunner.prototype.verifyConfig = function(config) {
VALID_WAIT_FOR_OPTIONS_NAMES));
}

waitForOptions = new Set(Object.keys(value.wait_for));
requiredOptions = VALID_WAIT_FOR_OPTIONS[value.wait_for];
waitForOptions = new Set(Object.keys(value.wait_for_options));
requiredOptions = VALID_WAIT_FOR_OPTIONS[value.wait_for].required_options;

missing = requiredOptions.difference(waitForOptions).array();

Expand All @@ -96,9 +102,9 @@ ProcessRunner.prototype.verifyConfig = function(config) {
}

// Verify dependencies exist
for (key in this._config) {
if (this._config.hasOwnProperty(key)) {
value = this._config[key];
for (key in config) {
if (config.hasOwnProperty(key)) {
value = config[key];
dependencies = value.depends || [];

dependencies.forEach(function(name) {
Expand Down Expand Up @@ -312,3 +318,5 @@ ProcessRunner.prototype._waitForSocket = function(obj, options, callback) {

connect();
};

exports.ProcessRunner = ProcessRunner;

0 comments on commit d813c25

Please sign in to comment.