Skip to content

Commit

Permalink
Command executor verbose logging (#899)
Browse files Browse the repository at this point in the history
* Parameterize verbosity of the OT-Node engine
  • Loading branch information
simonovic86 authored Mar 22, 2019
1 parent 82c22fa commit 26592a9
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 16 deletions.
3 changes: 2 additions & 1 deletion .origintrail_noderc.travis
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"node_private_key": "askRadomirIfYouNeedIt",
"database": {
"password": "root"
}
},
"commandExecutorVerboseLoggingEnabled": true
}
15 changes: 10 additions & 5 deletions config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@
"deposit_on_demand": true,
"dc_choose_time": 600000,
"requireApproval": false,
"litigationEnabled": true
"litigationEnabled": true,
"commandExecutorVerboseLoggingEnabled": false
},
"staging": {
"identity": null,
Expand Down Expand Up @@ -195,7 +196,8 @@
"deposit_on_demand": false,
"dc_choose_time": 600000,
"requireApproval": false,
"litigationEnabled": true
"litigationEnabled": true,
"commandExecutorVerboseLoggingEnabled": false
},
"stable": {
"identity": null,
Expand Down Expand Up @@ -294,7 +296,8 @@
"deposit_on_demand": false,
"dc_choose_time": 600000,
"requireApproval": false,
"litigationEnabled": true
"litigationEnabled": true,
"commandExecutorVerboseLoggingEnabled": false
},
"production": {
"identity": null,
Expand Down Expand Up @@ -396,7 +399,8 @@
"deposit_on_demand": false,
"dc_choose_time": 600000,
"requireApproval": false,
"litigationEnabled": true
"litigationEnabled": true,
"commandExecutorVerboseLoggingEnabled": false
},
"mariner": {
"identity": null,
Expand Down Expand Up @@ -498,6 +502,7 @@
"deposit_on_demand": false,
"dc_choose_time": 600000,
"requireApproval": true,
"litigationEnabled": false
"litigationEnabled": false,
"commandExecutorVerboseLoggingEnabled": false
}
}
30 changes: 23 additions & 7 deletions modules/command/command-executor.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,16 @@ class CommandExecutor {
this.started = false;

this.parallelism = QUEUE_PARALLELISM;
this.verboseLoggingEnabled = ctx.config.commandExecutorVerboseLoggingEnabled;

const that = this;
this.queue = async.queue(async (command, callback) => {
try {
while (!that.started) {
that.logger.trace('Command executor has not been started yet. Hibernating...');
if (that.verboseLoggingEnabled) {
that.logger.trace('Command executor has not been started yet. Hibernating...');
}

// eslint-disable-next-line
await sleep.sleep(1000);
}
Expand All @@ -66,7 +70,9 @@ class CommandExecutor {
constants.PERMANENT_COMMANDS,
async command => this._startDefaultCommand(command),
);
this.logger.trace('Command executor has been initialized...');
if (this.verboseLoggingEnabled) {
this.logger.trace('Command executor has been initialized...');
}
}

/**
Expand All @@ -75,7 +81,9 @@ class CommandExecutor {
*/
async start() {
this.started = true;
this.logger.trace('Command executor has been started...');
if (this.verboseLoggingEnabled) {
this.logger.trace('Command executor has been started...');
}
}

/**
Expand All @@ -88,7 +96,9 @@ class CommandExecutor {
started_at: now,
});

this.logger.trace(`Command ${command.name} and ID ${command.id} started.`);
if (this.verboseLoggingEnabled) {
this.logger.trace(`Command ${command.name} and ID ${command.id} started.`);
}

const handler = this.commandResolver.resolve(command.name);
if (command.deadline_at && now > command.deadline_at) {
Expand All @@ -110,7 +120,9 @@ class CommandExecutor {

const waitMs = (command.ready_at + command.delay) - now;
if (waitMs > 0) {
this.logger.trace(`Command ${command.name} with ID ${command.id} should be delayed`);
if (this.verboseLoggingEnabled) {
this.logger.trace(`Command ${command.name} with ID ${command.id} should be delayed`);
}
await this.add(command, Math.min(waitMs, constants.MAX_COMMAND_DELAY_IN_MILLS), false);
return;
}
Expand Down Expand Up @@ -151,7 +163,9 @@ class CommandExecutor {
}, command.transactional);

if (!result.repeat) {
this.logger.trace(`Command ${command.name} and ID ${command.id} processed.`);
if (this.verboseLoggingEnabled) {
this.logger.trace(`Command ${command.name} and ID ${command.id} processed.`);
}
result.children.forEach(async e => this.add(e, e.delay, false));
}
} catch (e) {
Expand Down Expand Up @@ -193,7 +207,9 @@ class CommandExecutor {
await CommandExecutor._delete(name);
const handler = this.commandResolver.resolve(name);
await this.add(handler.default(), 0, true);
this.logger.trace(`Permanent command ${name} created.`);
if (this.verboseLoggingEnabled) {
this.logger.trace(`Permanent command ${name} created.`);
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "origintrail_node",
"version": "3.0.1",
"version": "3.0.2",
"description": "OriginTrail node",
"main": ".eslintrc.js",
"config": {
Expand Down
2 changes: 1 addition & 1 deletion test/modules/utilities.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('Utilities module', () => {
'is_bootstrap_node', 'houston_password', 'enable_debug_logs_level', 'reverse_tunnel_address', 'reverse_tunnel_port',
'autoUpdater', 'bugSnag', 'network', 'dataSetStorage', 'dc_holding_time_in_minutes', 'dc_choose_time', 'dc_litigation_interval_in_minutes',
'dc_token_amount_per_holder', 'dh_max_holding_time_in_minutes', 'dh_min_litigation_interval_in_minutes', 'dh_min_token_price',
'erc725_identity_filepath', 'deposit_on_demand', 'requireApproval', 'litigationEnabled'],
'erc725_identity_filepath', 'deposit_on_demand', 'requireApproval', 'litigationEnabled', 'commandExecutorVerboseLoggingEnabled'],
`Some config items are missing in config for environment '${environment}'`,
);
assert.hasAllKeys(
Expand Down

0 comments on commit 26592a9

Please sign in to comment.