WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit a946873

Browse files
committed
Fix webhook timeout await
1 parent e64a3a9 commit a946873

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

workspaces/functions/api/deploy-webhook.ts

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -38,30 +38,34 @@ export default async function handler(req: VercelRequest, res: VercelResponse) {
3838
return res.status(200).json({ message: 'Deployment already scheduled' })
3939
}
4040

41-
timer = setTimeout(async () => {
42-
try {
43-
const response = await fetch(GITHUB_WORKFLOW_URL, {
44-
method: 'POST',
45-
headers: {
46-
Authorization: `Bearer ${GITHUB_TOKEN}`,
47-
Accept: 'application/vnd.github+json',
48-
'X-GitHub-Api-Version': '2022-11-28',
49-
},
50-
body: JSON.stringify({ ref: 'main' }),
51-
})
41+
await new Promise<void>((resolve, reject) => {
42+
timer = setTimeout(async () => {
43+
try {
44+
const response = await fetch(GITHUB_WORKFLOW_URL, {
45+
method: 'POST',
46+
headers: {
47+
Authorization: `Bearer ${GITHUB_TOKEN}`,
48+
Accept: 'application/vnd.github+json',
49+
'X-GitHub-Api-Version': '2022-11-28',
50+
},
51+
body: JSON.stringify({ ref: 'main' }),
52+
})
5253

53-
if (!response.ok) {
54-
console.error(`Failed to trigger workflow: ${response.statusText}`)
55-
} else {
56-
console.log('Deployment triggered')
54+
if (!response.ok) {
55+
console.error(`Failed to trigger workflow: ${response.statusText}`)
56+
} else {
57+
console.log('Deployment triggered')
58+
}
59+
resolve()
60+
} catch (error) {
61+
console.error('Error triggering deployment:', error)
62+
reject(error)
63+
} finally {
64+
// Reset the timer so that future requests can schedule a new dispatch.
65+
timer = null
5766
}
58-
} catch (error) {
59-
console.error('Error triggering deployment:', error)
60-
} finally {
61-
// Reset the timer so that future requests can schedule a new dispatch.
62-
timer = null
63-
}
64-
}, TIMEOUT)
67+
}, TIMEOUT)
68+
})
6569

6670
return res.status(200).json({ message: 'Deployment scheduled' })
6771
}

0 commit comments

Comments
 (0)