Skip to content

Commit

Permalink
feat: retry on alias creation error (#215)
Browse files Browse the repository at this point in the history
* feat: retry on alias creation error

* Add short sleep before retrying
  • Loading branch information
danmichaelo committed Jan 25, 2023
1 parent 2b2891b commit 225d234
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,23 @@ function slugify(str) {
return slug;
}

function retry(fn, retries) {
async function attempt(retry) {
try {
return await fn();
} catch (error) {
if (retry > retries) {
throw error;
} else {
core.info(`retrying: attempt ${retry + 1} / ${retries + 1}`);
await new Promise(resolve => setTimeout(resolve, 3000));
return attempt(retry + 1);
}
}
}
return attempt(1);
}

// Vercel
function getVercelBin() {
const input = core.getInput('vercel-version');
Expand Down Expand Up @@ -341,15 +358,14 @@ async function aliasDomainsToDeployment(deploymentUrl) {
core.info('using scope');
args.push('--scope', vercelScope);
}
const promises = aliasDomains.map(domain => {
return exec.exec('npx', [
vercelBin,
...args,
'alias',
deploymentUrl,
domain,
]);
});
const promises = aliasDomains.map(domain =>
retry(
() =>
exec.exec('npx', [vercelBin, ...args, 'alias', deploymentUrl, domain]),
2,
),
);

await Promise.all(promises);
}

Expand Down

5 comments on commit 225d234

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for team-scope-test ready!

✅ Preview
https://team-scope-test-coaal8tvd-dietfriends.vercel.app

Built with commit 225d234.
This pull request is being automatically deployed with vercel-action

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for express-basic-auth ready!

✅ Preview
https://express-basic-auth-cxqlf88g5-amond.vercel.app

Built with commit 225d234.
This pull request is being automatically deployed with vercel-action

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for zeit-now-deployment-action-example-static ready!

✅ Preview
https://zeit-now-deployment-action-example-static-k5kx42sbx-amond.vercel.app
https://master.static.vercel-action.amond.dev

Built with commit 225d234.
This pull request is being automatically deployed with vercel-action

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for vercel-action-example-nextjs ready!

✅ Preview
https://vercel-action-example-nextjs-dc6p8fsm8-amond.vercel.app
https://master.nextjs.vercel-action.amond.dev

Built with commit 225d234.
This pull request is being automatically deployed with vercel-action

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for zeit-now-deployment-action-example-angular ready!

✅ Preview
https://zeit-now-deployment-action-example-angular-47rypx728-amond.vercel.app

Built with commit 225d234.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.