Skip to content

Commit cb47f54

Browse files
committed
Add attemptsRemaining logic
1 parent 0a0d38f commit cb47f54

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

index.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ const getCurrentDeploy = async ({ siteId, sha }) => {
3737
}
3838
};
3939

40-
const waitForDeploy = async ({ siteId, sha }) => {
40+
const waitForDeploy = async ({ siteId, sha, attemptsRemaining }) => {
4141
const currentDeploy = await getCurrentDeploy({ siteId, sha });
42-
if (currentDeploy) {
42+
console.log(`Attempts remaining: ${attemptsRemaining}`);
43+
if (currentDeploy && attemptsRemaining > 0) {
4344
if (currentDeploy.state === 'ready') {
4445
console.log('deploy is ready');
4546
return currentDeploy;
@@ -48,7 +49,7 @@ const waitForDeploy = async ({ siteId, sha }) => {
4849
return null;
4950
} else {
5051
await new Promise((r) => setTimeout(r, 10000));
51-
return waitForDeploy({ siteId, sha });
52+
return waitForDeploy({ siteId, sha, attemptsRemaining: attemptsRemaining - 1 });
5253
}
5354
} else {
5455
return null;
@@ -57,13 +58,16 @@ const waitForDeploy = async ({ siteId, sha }) => {
5758

5859
const waitForLive = async ({ siteId, sha, MAX_TIMEOUT }) => {
5960
const iterations = MAX_TIMEOUT / 10;
61+
let attemptsRemaining = iterations;
6062
let currentDeploy = null;
63+
6164
for (let i = 0; i < iterations; i++) {
6265
try {
6366
currentDeploy = await getCurrentDeploy({ siteId, sha });
6467
if (currentDeploy) {
6568
break;
6669
} else {
70+
attemptsRemaining--;
6771
await new Promise((r) => setTimeout(r, 10000));
6872
}
6973
} catch (e) {
@@ -77,7 +81,7 @@ const waitForLive = async ({ siteId, sha, MAX_TIMEOUT }) => {
7781
core.setFailed(`Can't find Netlify related to commit: ${sha}`);
7882
}
7983

80-
currentDeploy = await waitForDeploy({ siteId, sha });
84+
currentDeploy = await waitForDeploy({ siteId, sha, attemptsRemaining });
8185
if (currentDeploy) {
8286
let url = currentDeploy.deploy_ssl_url;
8387
// compose permalink URL without Netlify Preview drawer

0 commit comments

Comments
 (0)