From bf0901e77fa7c8fe3d313b3c52d191f2dda35f92 Mon Sep 17 00:00:00 2001 From: Vicky Chijwani Date: Fri, 6 Oct 2017 02:15:28 +0530 Subject: [PATCH] Wrap Slack call in process.nextTick() to avoid blocking comment creation. --- .../server/hooks.js | 36 ++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/plugins/talk-plugin-slack-notifications/server/hooks.js b/plugins/talk-plugin-slack-notifications/server/hooks.js index a2f3ca743..bda9dc4f5 100644 --- a/plugins/talk-plugin-slack-notifications/server/hooks.js +++ b/plugins/talk-plugin-slack-notifications/server/hooks.js @@ -19,24 +19,26 @@ module.exports = { } } = result; const username = context.user.username; - const response = await fetch(SLACK_WEBHOOK_URL, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - timeout: SLACK_WEBHOOK_TIMEOUT, - body: JSON.stringify({ - attachments: [{ - text: text, - footer: `Comment by ${username}`, - ts: Math.floor(Date.parse(createdAt) / 1000), - }] - }), + process.nextTick(async () => { + const response = await fetch(SLACK_WEBHOOK_URL, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + timeout: SLACK_WEBHOOK_TIMEOUT, + body: JSON.stringify({ + attachments: [{ + text: text, + footer: `Comment by ${username}`, + ts: Math.floor(Date.parse(createdAt) / 1000), + }] + }), + }); + if (!response.ok) { + const responseText = await response.text(); + console.trace(`Posting to Slack failed with HTTP code ${response.status} and body '${responseText}'`); + } }); - if (!response.ok) { - const responseText = await response.text(); - console.trace(`Posting to Slack failed with HTTP code ${response.status} and body '${responseText}'`); - } return result; }, },