Wrap Slack call in process.nextTick() to avoid blocking comment creation.

This commit is contained in:
Vicky Chijwani
2017-10-06 02:17:45 +05:30
parent ba51645c87
commit bf0901e77f
@@ -19,24 +19,26 @@ module.exports = {
} }
} = result; } = result;
const username = context.user.username; const username = context.user.username;
const response = await fetch(SLACK_WEBHOOK_URL, { process.nextTick(async () => {
method: 'POST', const response = await fetch(SLACK_WEBHOOK_URL, {
headers: { method: 'POST',
'Content-Type': 'application/json', headers: {
}, 'Content-Type': 'application/json',
timeout: SLACK_WEBHOOK_TIMEOUT, },
body: JSON.stringify({ timeout: SLACK_WEBHOOK_TIMEOUT,
attachments: [{ body: JSON.stringify({
text: text, attachments: [{
footer: `Comment by ${username}`, text: text,
ts: Math.floor(Date.parse(createdAt) / 1000), 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; return result;
}, },
}, },