Skip to content

Commit

Permalink
Merge pull request #950 from microsoft/benibenj/publishWithRetry
Browse files Browse the repository at this point in the history
Retry on API request timeout
  • Loading branch information
benibenj committed Apr 11, 2024
2 parents 76560ba + d7fa866 commit 7346fec
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
30 changes: 22 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Expand Up @@ -35,12 +35,13 @@
"watch:test": "npm run test -- --watch"
},
"engines": {
"node": ">= 14"
"node": ">= 16"
},
"dependencies": {
"azure-devops-node-api": "^12.5.0",
"chalk": "^2.4.2",
"cheerio": "^1.0.0-rc.9",
"cockatiel": "^3.1.2",
"commander": "^6.2.1",
"form-data": "^4.0.0",
"glob": "^7.0.6",
Expand Down Expand Up @@ -69,7 +70,7 @@
"@types/mime": "^1",
"@types/minimatch": "^3.0.3",
"@types/mocha": "^7.0.2",
"@types/node": "^14.17.32",
"@types/node": "^16.11.7",
"@types/read": "^0.0.28",
"@types/semver": "^6.0.0",
"@types/tmp": "^0.2.2",
Expand Down
10 changes: 9 additions & 1 deletion src/publish.ts
Expand Up @@ -12,6 +12,7 @@ import { validatePublisher } from './validation';
import { GalleryApi } from 'azure-devops-node-api/GalleryApi';
import FormData from 'form-data';
import { basename } from 'path';
import { IterableBackoff, handleWhen, retry } from 'cockatiel';

const tmpName = promisify(tmp.tmpName);

Expand Down Expand Up @@ -249,7 +250,14 @@ async function _publishSignedPackage(api: GalleryApi, packageName: string, packa
header: `--${form.getBoundary()}${lineBreak}Content-Disposition: attachment; name=sigzip; filename=${sigzipName}${lineBreak}Content-Type: application/octet-stream${lineBreak}${lineBreak}`
});

return await api.publishExtensionWithPublisherSignature(undefined, form, manifest.publisher, manifest.name, extensionType);
const publishWithRetry = retry(handleWhen(err => err.message.includes('timeout')), {
maxAttempts: 3,
backoff: new IterableBackoff([5_000, 10_000, 20_000])
});

return await publishWithRetry.execute(async () => {
return await api.publishExtensionWithPublisherSignature(undefined, form, manifest.publisher, manifest.name, extensionType);
});
}

export interface IUnpublishOptions extends IPublishOptions {
Expand Down

0 comments on commit 7346fec

Please sign in to comment.