Skip to content

Commit 26a4386

Browse files
committed
fix: wait for invoke of lambda
1 parent 1d14332 commit 26a4386

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

src/serverless-webhook.js

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,30 @@ const lambda = new AWS.Lambda()
55

66
const isMessageForBot = require('./utils/isMessageForBot')
77

8+
function invokeLambda(payload) {
9+
const processIssueCommentPayload = JSON.stringify(payload)
10+
11+
return new Promise(function(resolve, reject) {
12+
lambda.invoke(
13+
{
14+
FunctionName: `${
15+
process.env.SERVICE_NAME_AND_STAGE
16+
}-processIssueComment`,
17+
InvocationType: 'Event',
18+
LogType: 'None',
19+
Payload: new Buffer(processIssueCommentPayload),
20+
},
21+
function(error, data) {
22+
if (error) {
23+
reject(error)
24+
} else {
25+
resolve(data)
26+
}
27+
},
28+
)
29+
})
30+
}
31+
832
module.exports.handler = async (event, context) => {
933
context.callbackWaitsForEmptyEventLoop = false
1034

@@ -43,20 +67,11 @@ module.exports.handler = async (event, context) => {
4367
}
4468
}
4569

46-
const processIssueCommentPayload = JSON.stringify({
70+
await invokeLambda({
4771
name,
4872
payload,
4973
})
5074

51-
lambda.invoke({
52-
FunctionName: `${
53-
process.env.SERVICE_NAME_AND_STAGE
54-
}-processIssueComment`,
55-
InvocationType: 'Event',
56-
LogType: 'None',
57-
Payload: new Buffer(processIssueCommentPayload),
58-
})
59-
6075
return {
6176
statusCode: 200,
6277
body: 'Accepted and processing comment',

0 commit comments

Comments
 (0)