Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(1961): Retry with new request package #2570

Merged
merged 1 commit into from
Sep 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions features/support/world.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ const { ID } = require('./constants');
* @param {Function} retryWithMergedOptions
* @return {Object} Build response
*/
function buildRetryStrategy(response, retryWithMergedOptions) {
function buildRetryStrategy(response) {
if (response.body.status === 'QUEUED' || response.body.status === 'RUNNING') {
retryWithMergedOptions({});
throw new Error('Retry limit reached');
}

return response;
Expand Down Expand Up @@ -196,7 +196,8 @@ function CustomWorld({ attach, parameters }) {
request({
url: `${this.instance}/${this.namespace}/builds/${buildID}`,
method: 'GET',
retryOptions: {
retry: {
statusCodes: [200],
limit: 25,
calculateDelay: ({ computedValue }) => (computedValue ? 15000 : 0)
},
Expand Down
2 changes: 1 addition & 1 deletion features/workflow.feature
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Feature: Workflow
Then the PR job of "AFTER-SIMPLE" is triggered from PR job of "SIMPLE"
And that "AFTER-SIMPLE" PR build uses the same SHA as the "SIMPLE" PR build
And the "AFTER-SIMPLE" PR build succeeded

@ignore
Scenario: Branch filtering (a pull request is opened to the master branch)
Given an existing pipeline on "master" branch with the workflow jobs:
Expand Down
10 changes: 5 additions & 5 deletions plugins/pipelines/caches/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ const RETRY_LIMIT = 3;
* @param {Function} retryWithMergedOptions
* @return {Object} Response
*/
const retryStrategyFn = (response, retryWithMergedOptions) => {
const retryStrategyFn = response => {
if (Math.floor(response.statusCode / 100) !== 2) {
retryWithMergedOptions({});
throw new Error('Retry limit reached');
}

return response;
Expand Down Expand Up @@ -78,19 +78,19 @@ async function invoke(request) {
}

if (retryStrategyFn) {
const retryOptions = {
const retry = {
limit: RETRY_LIMIT,
calculateDelay: ({ computedValue }) => (computedValue ? RETRY_DELAY * 1000 : 0) // in ms
};

if (method === 'POST') {
Object.assign(retryOptions, {
Object.assign(retry, {
methods: ['POST']
});
}

Object.assign(options, {
retryOptions,
retry,
hooks: {
afterResponse: [retryStrategyFn]
}
Expand Down