diff --git a/src/index.js b/src/index.js index e74f07522..fa89199d7 100644 --- a/src/index.js +++ b/src/index.js @@ -11,7 +11,6 @@ import log from './log.js'; import datadog from './datadog.js'; import * as jsDelivr from './jsDelivr/index.js'; import * as sentry from './utils/sentry.js'; -import wait from './utils/wait.js'; log.info('🗿 npm ↔️ Algolia replication starts ⛷ 🐌 🛰'); @@ -328,9 +327,6 @@ async function watch(stateManager, mainIndex) { async function error(err) { sentry.report(err); - - // Wait for sentry to report the error on their API - await wait(5000); - + await sentry.drain(); process.exit(1); // eslint-disable-line no-process-exit } diff --git a/src/utils/sentry.js b/src/utils/sentry.js index 8f1a0c63f..607527c52 100644 --- a/src/utils/sentry.js +++ b/src/utils/sentry.js @@ -9,7 +9,7 @@ Sentry.init({ serverName: 'npm-search', }); -function report(err, extra = {}) { +export function report(err, extra = {}) { log.error(err.message); if (!process.env.SENTRY_DSN) { log.error(err); @@ -22,4 +22,10 @@ function report(err, extra = {}) { }); } -export { report }; +export function drain() { + const client = Sentry.getCurrentHub().getClient(); + if (client) { + return client.close(2000); + } + return Promise.resolve(); +} diff --git a/src/utils/wait.js b/src/utils/wait.js deleted file mode 100644 index 8c08332dd..000000000 --- a/src/utils/wait.js +++ /dev/null @@ -1,7 +0,0 @@ -export default waitTime => { - if (waitTime <= 0) { - return Promise.resolve(); - } - - return new Promise(resolve => setTimeout(resolve, waitTime)); -};