Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Production Release #4

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 24 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const asclepius = require('asclepius');
const nullLogger = require('null-logger');

const sequelizeHealthcheck = (sequelize, logger = nullLogger) => asclepius.healthcheck(
const defaultTimeout = 500;

const sequelizeHealthcheck = (sequelize, logger = nullLogger, timeout = defaultTimeout) => asclepius.healthcheck(
'psql',
() =>
sequelize
Expand All @@ -11,10 +13,10 @@ const sequelizeHealthcheck = (sequelize, logger = nullLogger) => asclepius.healt
logger.error('PSQL Healthcheck Failed. Reason:', err);
return Promise.reject(err.name);
}),
500
timeout
);

const redisHealthcheck = (redis, logger = nullLogger) => asclepius.healthcheck(
const redisHealthcheck = (redis, logger = nullLogger, timeout = defaultTimeout) => asclepius.healthcheck(
'redis',
() =>
new Promise((resolve, reject) => {
Expand All @@ -26,10 +28,10 @@ const redisHealthcheck = (redis, logger = nullLogger) => asclepius.healthcheck(
return resolve();
});
}),
500
timeout
);

const elasticsearchHealthcheck = (elasticsearch, logger = nullLogger) => asclepius.healthcheck(
const elasticsearchHealthcheck = (elasticsearch, logger = nullLogger, timeout = defaultTimeout) => asclepius.healthcheck(
'elasticsearch',
() =>
elasticsearch
Expand All @@ -39,22 +41,32 @@ const elasticsearchHealthcheck = (elasticsearch, logger = nullLogger) => asclepi
logger.error('Elasticsearch Healthcheck Failed. Reason:', err);
return Promise.reject('Ping Failed');
}),
500
timeout
);

const processHealthcheck = asclepius.healthcheck(
'process',
() => Promise.resolve(),
500
defaultTimeout
);

module.exports = {
setup: ({ sequelize = null, redis = null, elasticsearch = null, logger = nullLogger } = {}) => {
const _buildHealthCheckArray = ({ sequelize = null, redis = null, elasticsearch = null, logger = nullLogger, timeout = defaultTimeout } = {}) => {
const healthchecks = [processHealthcheck];

if (sequelize) healthchecks.push(sequelizeHealthcheck(sequelize, logger));
if (elasticsearch) healthchecks.push(elasticsearchHealthcheck(elasticsearch, logger));
if (redis) healthchecks.push(redisHealthcheck(redis, logger));
if (sequelize) healthchecks.push(sequelizeHealthcheck(sequelize, logger, timeout));
if (elasticsearch) healthchecks.push(elasticsearchHealthcheck(elasticsearch, logger, timeout));
if (redis) healthchecks.push(redisHealthcheck(redis, logger, timeout));

return healthchecks;
}

module.exports = {
setup: ({ sequelize = null, redis = null, elasticsearch = null, logger = nullLogger, timeout = defaultTimeout } = {}) => {
const healthchecks = _buildHealthCheckArray({ sequelize, redis, elasticsearch, logger, timeout });
return asclepius.makeRoute(healthchecks);
},
runner: ({ sequelize = null, redis = null, elasticsearch = null, logger = nullLogger, timeout = defaultTimeout } = {}) => {
const healthchecks = _buildHealthCheckArray({ sequelize, redis, elasticsearch, logger, timeout });
return asclepius.makeRunner(healthchecks);
}
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "asclepius-standard",
"version": "1.0.2",
"version": "1.1.0",
"description": "Asclepius Standard Configuration",
"repository": "[email protected]:ordermentum/asclepius-standard.git",
"main": "index.js",
Expand Down
5 changes: 5 additions & 0 deletions renovate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": [
"config:base"
]
}