diff --git a/packages/nylas-api/app.js b/packages/nylas-api/app.js index dc9b08e08..8199a9687 100644 --- a/packages/nylas-api/app.js +++ b/packages/nylas-api/app.js @@ -14,6 +14,10 @@ const {DatabaseConnector, SchedulerUtils, Logger} = require(`nylas-core`); global.Promise = require('bluebird'); global.Logger = Logger.createLogger('nylas-k2-api') +const onUnhandledError = (err) => global.Logger.fatal(err, 'Unhandled error') +process.on('uncaughtException', onUnhandledError) +process.on('unhandledRejection', onUnhandledError) + const server = new Hapi.Server({ connections: { router: { diff --git a/packages/nylas-sync/app.js b/packages/nylas-sync/app.js index ac81a02f1..16bf4509f 100644 --- a/packages/nylas-sync/app.js +++ b/packages/nylas-sync/app.js @@ -5,6 +5,10 @@ const SyncProcessManager = require('./sync-process-manager'); global.Logger = Logger.createLogger('nylas-k2-sync') +const onUnhandledError = (err) => global.Logger.fatal(err, 'Unhandled error') +process.on('uncaughtException', onUnhandledError) +process.on('unhandledRejection', onUnhandledError) + const manager = new SyncProcessManager(); DatabaseConnector.forShared().then((db) => { diff --git a/packages/nylas-sync/sync-process-manager.js b/packages/nylas-sync/sync-process-manager.js index c32d2aa8b..3d205c384 100644 --- a/packages/nylas-sync/sync-process-manager.js +++ b/packages/nylas-sync/sync-process-manager.js @@ -61,13 +61,13 @@ class SyncProcessManager { updateHeartbeat() { const key = HEARTBEAT_FOR(IDENTITY); const client = PubsubConnector.broadcastClient(); - client.setAsync(key, Date.now()).then(() => - client.expireAsync(key, HEARTBEAT_EXPIRES) - ).then(() => - this._logger.info({ - accounts_syncing_count: Object.keys(this._workers).length, - }, "ProcessManager: 💘") - ) + client.setAsync(key, Date.now()) + .then(() => client.expireAsync(key, HEARTBEAT_EXPIRES)) + .then(() => { + this._logger.info({ + accounts_syncing_count: Object.keys(this._workers).length, + }, "ProcessManager: 💘") + }) } onSigInt() {