Skip to content
This repository has been archived by the owner on Jan 18, 2019. It is now read-only.

Commit

Permalink
Merge pull request #116 from terascope/shutdown-improvements
Browse files Browse the repository at this point in the history
v0.3.0 process shutdown improvements
  • Loading branch information
jsnoble authored Sep 18, 2018
2 parents ac361b4 + b846ba7 commit 7d13acb
Show file tree
Hide file tree
Showing 13 changed files with 831 additions and 1,696 deletions.
16 changes: 8 additions & 8 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
{
"extends": "airbnb",
"extends": "airbnb-base",
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "script",
"ecmaFeatures": {
"experimentalObjectRestSpread": true
}
"ecmaVersion": 8,
"sourceType": "script"
},
"env": {
"node": true,
"jasmine": true
"jasmine": true,
"jest": true
},
"rules": {
"no-underscore-dangle": "off",
Expand All @@ -24,9 +22,11 @@
"no-restricted-globals": ["error", "isFinite"],
"func-names": ["error", "as-needed"],
"semi-spacing": "error",
"function-paren-newline": ["error", "consistent"],
"rest-spread-spacing": ["error"],
"no-path-concat": "error",
"no-debugger": "error",
"handle-callback-err": ["error", "error"]
"handle-callback-err": ["error", "error"],
"import/no-extraneous-dependencies": "off"
}
}
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ deploy:
provider: npm
email: [email protected]
api_key:
secure: PW9Cj8++ShCa6Hh2lfmScAXgDEOZEicwLscN5vojz9tqNnd4f9qGY9FOinWXUsmPYhdcafr83aGTxMCjmTLQTmflbA0f76HMRn2zGW4zkbuD1/52pBsJ0Peqtzk5WHf6vhi7VJZxdZV/f3BFChFIWiz6VXlewdEFNHRl6uUwEBbuVbZdDuVBzxJN5tGvwFzxSEDH/18tTx+NceXN/Obb2VI7mjO38jhsHcrXasMvimtrZfbBH2oavE6kQ5F4jrYVSvC9P6PCAXscUXA8sFQlU+3Jtyk5OQxriqRRCVOHEnujYiu6DMjj/vWUEZ5JcMSNSJ8/E7ZGeoDBLI8VT5J7rd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.[0-9]+\.[0-9]+
Expand Down
11 changes: 0 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,6 @@ module.exports = function module(config) {
// logger as it stands this function is very confusing
loggerClient(context, context.logger, loggingConnection);

// The master shouldn't need these connections.
if (!context.cluster.isMaster) {
// We have to load this here so it uses the same mongoose instance
// This is really a teraserver dependency and doesn't belong here.
// It's a problem when teraserver is loaded from node_modules.
if (config.baucis) {
logger.info('Loading module Baucis');
context.baucis = require('baucis');
}
}

if (config.script) {
config.script(context);
/**
Expand Down
39 changes: 19 additions & 20 deletions lib/connectors/elasticsearch.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,48 @@
'use strict';

var Promise = require('bluebird');
const Promise = require('bluebird');

function logWrapper(logger) {

return function() {
return function () {
this.error = logger.error.bind(logger);
this.warning = logger.warn.bind(logger);
this.info = logger.info.bind(logger);
this.debug = logger.debug.bind(logger);
this.trace = function(method, requestUrl, body, responseBody, responseStatus) {
this.trace = function (method, requestUrl, body, responseBody, responseStatus) {
logger.trace({
method: method,
requestUrl: requestUrl,
body: body,
responseBody: responseBody,
responseStatus: responseStatus
method,
requestUrl,
body,
responseBody,
responseStatus
});
};
this.close = function() {
this.close = function () {
};
}
};
}

function create(customConfig, logger) {
var elasticsearch = require('elasticsearch');
const elasticsearch = require('elasticsearch');

logger.info("Using elasticsearch hosts: " + customConfig.host);
logger.info(`Using elasticsearch hosts: ${customConfig.host}`);

customConfig.defer = function () {
return Promise.defer();
};
var client = new elasticsearch.Client(customConfig);
const client = new elasticsearch.Client(customConfig);

return {
client: client,
client,
log: logWrapper(logger)
}
};
}

function config_schema() {
return {
host: {
doc: '',
default: ["127.0.0.1:9200"]
default: ['127.0.0.1:9200']
},
sniffOnStart: {
doc: '',
Expand All @@ -65,10 +64,10 @@ function config_schema() {
doc: '',
default: 3
}
}
};
}

module.exports = {
create: create,
config_schema: config_schema
create,
config_schema
};
20 changes: 10 additions & 10 deletions lib/connectors/hdfs.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
'use strict';

var events = require('events');
const events = require('events');

function create(customConfig, logger) {
var hdfsClient = require('node-webhdfs').WebHDFSClient;
logger.info("Using hdfs hosts: " + customConfig.host);
const hdfsClient = require('node-webhdfs').WebHDFSClient;
logger.info(`Using hdfs hosts: ${customConfig.host}`);

// TODO: there's no error handling here at all???
var client = new hdfsClient(customConfig);
const client = new hdfsClient(customConfig);

return {
client: client
}
client
};
}

function config_schema() {
Expand All @@ -32,10 +32,10 @@ function config_schema() {
doc: '',
default: '/webhdfs/v1'
}
}
};
}

module.exports = {
create: create,
config_schema: config_schema
};
create,
config_schema
};
36 changes: 17 additions & 19 deletions lib/connectors/hdfs_ha.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
'use strict';

var events = require('events');
var Promise = require('bluebird');
var _ = require('lodash');
const events = require('events');
const Promise = require('bluebird');
const _ = require('lodash');

function create(customConfig, logger) {
var hdfsClient = require('node-webhdfs').WebHDFSClient;
const hdfsClient = require('node-webhdfs').WebHDFSClient;

var highAvailibility = false;
var currentNameNode;
let highAvailibility = false;
let currentNameNode;

if (Array.isArray(customConfig.namenode_host)) {
currentNameNode = customConfig.namenode_host[0];
customConfig.namenode_list = customConfig.namenode_host;
highAvailibility = true;
}
else {
} else {
currentNameNode = customConfig.namenode_host;
}

var config = _.assign({}, customConfig, {namenode_host: currentNameNode});
var client = new hdfsClient(config);
const config = _.assign({}, customConfig, { namenode_host: currentNameNode });
const client = new hdfsClient(config);

logger.info(`Using hdfs hosts: ${currentNameNode}, high-availability: ${highAvailibility}`);

return {
client: Promise.promisifyAll(client)
}
};
}

function config_schema() {
Expand All @@ -43,28 +42,27 @@ function config_schema() {
namenode_host: {
doc: 'a single host, or multiple hosts listed in an array',
default: null,
format: function(val) {
format(val) {
if (typeof val === 'string') {

return;
}
if (Array.isArray(val)) {
if (val.length < 2) {
throw new Error("namenode_host must have at least two namenodes listed in the array")
throw new Error('namenode_host must have at least two namenodes listed in the array');
}
return;
}
throw new Error('namenode_host configuration must be set to an array for high availability or a string')
throw new Error('namenode_host configuration must be set to an array for high availability or a string');
}
},
path_prefix: {
doc: 'endpoint for hdfs web interface',
default: '/webhdfs/v1'
}
}
};
}

module.exports = {
create: create,
config_schema: config_schema
};
create,
config_schema
};
26 changes: 13 additions & 13 deletions lib/connectors/mongodb.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
'use strict';

var events = require('events');
const events = require('events');

function create(customConfig, logger) {
var mongoose = require("mongoose");
const mongoose = require('mongoose');
// TODO: rework configuration to allow incoming config to be a full mongo config
logger.info("Using mongo connection string: " + customConfig.servers);
logger.info(`Using mongo connection string: ${customConfig.servers}`);

var serverConfig = {
const serverConfig = {
server: {
auto_reconnect: true,
socketOptions: {keepAlive: 1, connectTimeoutMS: 30000}
socketOptions: { keepAlive: 1, connectTimeoutMS: 30000 }
}
};

Expand All @@ -25,27 +25,27 @@ function create(customConfig, logger) {
};
}

mongoose.connect(customConfig.servers, serverConfig, function(error) {
mongoose.connect(customConfig.servers, serverConfig, (error) => {
if (error) {
logger.error("Could not connect to Mongo DB: " + error);
logger.error(`Could not connect to Mongo DB: ${error}`);
}
});

return {
client: mongoose
}
};
}

function config_schema() {
return {
servers: {
doc: '',
default: "mongodb://localhost:27017/test"
default: 'mongodb://localhost:27017/test'
}
}
};
}

module.exports = {
create: create,
config_schema: config_schema
};
create,
config_schema
};
21 changes: 10 additions & 11 deletions lib/connectors/redis.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
'use strict';

var _ = require('lodash');
var redis = require('redis');
var events = require('events');
const _ = require('lodash');
const redis = require('redis');
const events = require('events');

function create(customConfig, logger) {
logger.info("Using redis host: " + customConfig.host);
logger.info(`Using redis host: ${customConfig.host}`);

var client = redis.createClient(customConfig.port, customConfig.host);
const client = redis.createClient(customConfig.port, customConfig.host);

return {
client: client
}
client
};
}

function config_schema() {
Expand All @@ -24,11 +24,10 @@ function config_schema() {
doc: '',
default: 6379
}
}
};
}

module.exports = {
create: create,
config_schema: config_schema
create,
config_schema
};

20 changes: 10 additions & 10 deletions lib/connectors/statsd.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
'use strict';

var events = require('events');
const events = require('events');

function create(customConfig, logger) {
var StatsD = require('node-statsd').StatsD;
logger.info("Using statsd host: " + customConfig.host);
const StatsD = require('node-statsd').StatsD;
logger.info(`Using statsd host: ${customConfig.host}`);

var client = new StatsD(customConfig);
const client = new StatsD(customConfig);

return {
client: client
}
client
};
}

function config_schema() {
Expand All @@ -23,11 +23,11 @@ function config_schema() {
doc: '',
default: false
}
}
};
}

module.exports = {
create: create,
config_schema: config_schema
create,
config_schema

};
};
Loading

0 comments on commit 7d13acb

Please sign in to comment.