mirror of
https://github.com/wassname/talk.git
synced 2026-06-28 09:29:59 +08:00
Wrap Slack call in process.nextTick() to avoid blocking comment creation.
This commit is contained in:
@@ -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;
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user