Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

lightship

Package Overview
Dependencies
Maintainers
1
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lightship - npm Package Compare versions

Comparing version 5.1.0 to 6.0.0

240

dist/factories/createLightship.js

@@ -26,12 +26,3 @@ "use strict";

function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
// eslint-disable-next-line fp/no-events
const log = _Logger.default.child({

@@ -53,5 +44,6 @@ namespace: 'factories/createLightship'

const shutdownHandlers = [];
const configuration = { ...defaultConfiguration,
...userConfiguration
};
const configuration = _objectSpread({}, defaultConfiguration, {}, userConfiguration);
if (configuration.gracefulShutdownTimeout < configuration.shutdownHandlerTimeout) {

@@ -117,121 +109,93 @@ throw new Error('gracefulShutdownTimeout cannot be lesser than shutdownHandlerTimeout.');

const shutdown =
/*#__PURE__*/
function () {
var _ref = _asyncToGenerator(function* () {
if (serverIsShuttingDown) {
log.warn('server is already shutting down');
return;
}
const shutdown = async () => {
if (serverIsShuttingDown) {
log.warn('server is already shutting down');
return;
}
log.info('received request to shutdown the service');
let gracefulShutdownTimeoutId;
log.info('received request to shutdown the service');
let gracefulShutdownTimeoutId;
if (configuration.gracefulShutdownTimeout !== Infinity) {
gracefulShutdownTimeoutId = setTimeout(() => {
log.warn('graceful shutdown timeout; forcing termination'); // eslint-disable-next-line no-process-exit
if (configuration.gracefulShutdownTimeout !== Infinity) {
gracefulShutdownTimeoutId = setTimeout(() => {
log.warn('graceful shutdown timeout; forcing termination'); // eslint-disable-next-line no-process-exit
process.exit(1);
}, configuration.gracefulShutdownTimeout); // $FlowFixMe
process.exit(1);
}, configuration.gracefulShutdownTimeout); // $FlowFixMe
gracefulShutdownTimeoutId.unref();
} // @see https://github.com/gajus/lightship/issues/12
gracefulShutdownTimeoutId.unref();
} // @see https://github.com/gajus/lightship/issues/12
serverIsReady = true;
serverIsShuttingDown = true;
serverIsReady = true;
serverIsShuttingDown = true;
if (beacons.length) {
yield new Promise(resolve => {
const check = () => {
log.debug('checking if there are live beacons');
if (beacons.length) {
await new Promise(resolve => {
const check = () => {
log.debug('checking if there are live beacons');
if (beacons.length > 0) {
log.info({
beacons
}, 'program termination is on hold because there are live beacons');
} else {
log.info('there are no live beacons; proceeding to terminate the Node.js process');
eventEmitter.off('beaconStateChange', check);
resolve();
}
};
if (beacons.length > 0) {
log.info({
beacons
}, 'program termination is on hold because there are live beacons');
} else {
log.info('there are no live beacons; proceeding to terminate the Node.js process');
eventEmitter.off('beaconStateChange', check);
resolve();
}
};
eventEmitter.on('beaconStateChange', check);
check();
});
}
eventEmitter.on('beaconStateChange', check);
check();
});
}
if (gracefulShutdownTimeoutId) {
clearTimeout(gracefulShutdownTimeoutId);
}
if (gracefulShutdownTimeoutId) {
clearTimeout(gracefulShutdownTimeoutId);
}
let shutdownHandlerTimeoutId;
let shutdownHandlerTimeoutId;
if (configuration.shutdownHandlerTimeout !== Infinity) {
shutdownHandlerTimeoutId = setTimeout(() => {
log.warn('shutdown handler timeout; forcing termination'); // eslint-disable-next-line no-process-exit
if (configuration.shutdownHandlerTimeout !== Infinity) {
shutdownHandlerTimeoutId = setTimeout(() => {
log.warn('shutdown handler timeout; forcing termination'); // eslint-disable-next-line no-process-exit
process.exit(1);
}, configuration.shutdownHandlerTimeout); // $FlowFixMe
process.exit(1);
}, configuration.shutdownHandlerTimeout); // $FlowFixMe
shutdownHandlerTimeoutId.unref();
}
shutdownHandlerTimeoutId.unref();
}
log.debug('running %d shutdown handler(s)', shutdownHandlers.length);
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
log.debug('running %d shutdown handler(s)', shutdownHandlers.length);
for (const shutdownHandler of shutdownHandlers) {
try {
for (var _iterator = shutdownHandlers[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
const shutdownHandler = _step.value;
try {
yield shutdownHandler();
} catch (error) {
log.error({
error: (0, _serializeError.serializeError)(error)
}, 'shutdown handler produced an error');
}
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
await shutdownHandler();
} catch (error) {
log.error({
error: (0, _serializeError.serializeError)(error)
}, 'shutdown handler produced an error');
}
}
if (shutdownHandlerTimeoutId) {
clearTimeout(shutdownHandlerTimeoutId);
if (shutdownHandlerTimeoutId) {
clearTimeout(shutdownHandlerTimeoutId);
}
log.debug('all shutdown handlers have run to completion; proceeding to terminate the Node.js process');
server.close(error => {
if (error) {
log.error({
error: (0, _serializeError.serializeError)(error)
}, 'server was terminated with an error');
}
log.debug('all shutdown handlers have run to completion; proceeding to terminate the Node.js process');
server.close(error => {
if (error) {
log.error({
error: (0, _serializeError.serializeError)(error)
}, 'server was terminated with an error');
}
});
setTimeout(() => {
log.warn('process did not exit on its own; investigate what is keeping the event loop active'); // eslint-disable-next-line no-process-exit
process.exit(1);
}, 1000) // $FlowFixMe
.unref();
});
setTimeout(() => {
log.warn('process did not exit on its own; investigate what is keeping the event loop active'); // eslint-disable-next-line no-process-exit
return function shutdown() {
return _ref.apply(this, arguments);
};
}();
process.exit(1);
}, 1000) // $FlowFixMe
.unref();
};

@@ -241,29 +205,9 @@ if (modeIsLocal) {

} else {
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
try {
for (var _iterator2 = configuration.signals[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
const signal = _step2.value;
process.on(signal, () => {
log.debug({
signal
}, 'received a shutdown signal');
shutdown();
});
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
for (const signal of configuration.signals) {
process.on(signal, () => {
log.debug({
signal
}, 'received a shutdown signal');
shutdown();
});
}

@@ -278,18 +222,10 @@ }

return {
die: function () {
var _die = _asyncToGenerator(function* () {
log.trace({
beacon
}, 'beacon has been killed');
beacons.splice(beacons.indexOf(beacon), 1);
eventEmitter.emit('beaconStateChange');
yield (0, _delay.default)(0);
});
function die() {
return _die.apply(this, arguments);
}
return die;
}()
die: async () => {
log.trace({
beacon
}, 'beacon has been killed');
beacons.splice(beacons.indexOf(beacon), 1);
eventEmitter.emit('beaconStateChange');
await (0, _delay.default)(0);
}
};

@@ -296,0 +232,0 @@ };

@@ -8,3 +8,3 @@ "use strict";

enumerable: true,
get: function get() {
get: function () {
return _createLightship.default;

@@ -11,0 +11,0 @@ }

@@ -8,3 +8,3 @@ "use strict";

enumerable: true,
get: function get() {
get: function () {
return _isKubernetes.default;

@@ -11,0 +11,0 @@ }

@@ -52,3 +52,3 @@ {

"engines": {
"node": ">8"
"node": ">10"
},

@@ -89,3 +89,3 @@ "husky": {

},
"version": "5.1.0"
"version": "6.0.0"
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc