UNPKG

@aimee-blue/ab-service-kit

Version:
78 lines (63 loc) 2.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.start = start; var _startCore = require("./startCore"); var _initializeLogger = require("./setup/initializeLogger"); function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } function start(config) { (0, _initializeLogger.initializeLoggerOrFallback)(config).then(logger => { startWithLoggerAndConfig(config, logger); }).catch(() => { // logger initialization cannot throw // this handler here is to supress warning return; }); } let shutdownRequests = 0; function startWithLoggerAndConfig(config, logger) { function handleError(exc) { logger.error('💥 ', exc); process.exit(1); } function finish() { process.exitCode = 0; } async function run() { process.setUncaughtExceptionCaptureCallback(handleError); process.on('SIGINT', () => { logger.log('\nShutting down due to SIGINT...\n'); shutdown().then(finish).catch(handleError); shutdownRequests += 1; if (shutdownRequests > 1) { Promise.resolve().then(() => _interopRequireWildcard(require('wtfnode'))).then(mod => { console.log('== Open Handles =='); mod.dump(); console.log(' '); }).catch(err => { console.log(err); }); } if (shutdownRequests > 5) { process.exit(1); } }); process.on('SIGTERM', () => { logger.log('\nShutting down due to SIGTERM...\n'); shutdown().then(finish).catch(handleError); }); const teardown = await (0, _startCore.startCore)(config, undefined, logger); let isShuttingDown = false; const shutdown = async () => { if (isShuttingDown) { return; } isShuttingDown = true; await teardown(); }; } run().catch(handleError); } //# sourceMappingURL=start.js.map