Skip to content

Commit cbe4edf

Browse files
Merge pull request #139 from codefresh-io/CR-13431-cf-api-retries
CR-13431 add CF_API_RETRIES
2 parents ca49f60 + d58118f commit cbe4edf

File tree

5 files changed

+32
-5
lines changed

5 files changed

+32
-5
lines changed

config/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ class Config {
109109
branchNormalized: process.env.CF_BRANCH_TAG_NORMALIZED,
110110
storageIntegration: process.env.CF_STORAGE_INTEGRATION,
111111
logLevel: logLevelsMap[process.env.REPORT_LOGGING_LEVEL] || INFO,
112+
retriesForCodefreshAPI: Number(process.env.CF_API_RETRIES) || 0,
112113
sourceReportFolderName: (allureDir || 'allure-results').trim(),
113114
reportDir: ((reportDir || '').trim()) || undefined,
114115
reportPath: ((reportPath || '').trim()).replace(/\/$/, ''),

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cf-docker-test-reporting",
3-
"version": "1.0.4",
3+
"version": "1.0.5",
44
"description": "Generate test report",
55
"repository": {
66
"type": "git",
@@ -37,6 +37,7 @@
3737
"recursive-readdir-sync": "^1.0.6",
3838
"request": "^2.88.0",
3939
"request-promise": "^4.2.2",
40+
"retry-request" : "5.0.2",
4041
"rimraf": "^2.7.1"
4142
},
4243
"devDependencies": {

src/api/index.js

+19-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
1+
const _ = require('lodash');
12
const rp = require('request-promise');
3+
const Promise = require('bluebird');
4+
const retryRequest = require('retry-request');
25

36
class CodefreshAPI {
7+
8+
static async sendRequest(config, opts) {
9+
if (config.env.retriesForCodefreshAPI) {
10+
opts.retries = config.env.retriesForCodefreshAPI;
11+
const response = await Promise.fromCallback(cb => retryRequest(opts, cb));
12+
const body = _.get(response, 'body');
13+
if (response.statusCode !== 200) {
14+
throw new Error(body);
15+
}
16+
return body;
17+
}
18+
return rp(opts);
19+
}
20+
421
static async createAnnotation({ config, value }) {
522
// this query use proxy ability to replace :account_id to currentAccountID
623
// this ability use because we don`t know accountId
@@ -19,7 +36,7 @@ class CodefreshAPI {
1936
json: true,
2037
};
2138

22-
return rp(createAnnotationOpts);
39+
return this.sendRequest(config, createAnnotationOpts);
2340
}
2441

2542
static async getProcessById({ id, config }) {
@@ -33,7 +50,7 @@ class CodefreshAPI {
3350
let process;
3451

3552
try {
36-
const processRes = await rp(opts);
53+
const processRes = await this.sendRequest(config, opts);
3754
process = JSON.parse(processRes);
3855
} catch (e) {
3956
throw new Error('Error during getting process info');

src/storageConfig/StorageConfigProvider.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
const _ = require('lodash');
2-
const rp = require('request-promise');
32
const VariableResolver = require('../ variableResolver/VariableResolver');
43
const storageTypesMap = require('./types');
54
const storageTypes = require('./storageTypes');
65
const fs = require('fs');
6+
const CodefreshAPI = require('../api');
77

88
class StorageConfigProvider {
99
constructor({ config }) {
@@ -29,7 +29,7 @@ class StorageConfigProvider {
2929
};
3030

3131
try {
32-
return await rp(opts);
32+
return await CodefreshAPI.sendRequest(config, opts);
3333
} catch (e) {
3434
const infoErrMsg = `Can't get storage integration: ${this.integrationName}`;
3535
if (config.env.logLevel === config.logLevels.DEBUG) {

yarn.lock

+8
Original file line numberDiff line numberDiff line change
@@ -4152,6 +4152,14 @@ restore-cursor@^1.0.1:
41524152
exit-hook "^1.0.0"
41534153
onetime "^1.0.0"
41544154

4155+
4156+
version "5.0.2"
4157+
resolved "https://registry.yarnpkg.com/retry-request/-/retry-request-5.0.2.tgz#143d85f90c755af407fcc46b7166a4ba520e44da"
4158+
integrity sha512-wfI3pk7EE80lCIXprqh7ym48IHYdwmAAzESdbU8Q9l7pnRCk9LEhpbOTNKjz6FARLm/Bl5m+4F0ABxOkYUujSQ==
4159+
dependencies:
4160+
debug "^4.1.1"
4161+
extend "^3.0.2"
4162+
41554163
retry-request@^4.0.0:
41564164
version "4.1.3"
41574165
resolved "https://registry.yarnpkg.com/retry-request/-/retry-request-4.1.3.tgz#d5f74daf261372cff58d08b0a1979b4d7cab0fde"

0 commit comments

Comments
 (0)