Skip to content

Commit 20f7078

Browse files
timeouts (#317)
* request timeout configurable * set specific request timeout for teams synchronize * add spinner * update sdk dep * update version
1 parent 3166c11 commit 20f7078

File tree

5 files changed

+38
-12
lines changed

5 files changed

+38
-12
lines changed

lib/interface/cli/commad-line-interface.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ async function startCommandLine() {
2222
configPath: PROCESS_ARGV.cfconfig,
2323
spec: { json: openapi },
2424
request: _.defaultsDeep({
25+
timeout: PROCESS_ARGV.requestTimeout,
2526
headers: {
2627
'User-Agent': `codefresh-cli-v${version}`,
2728
'Codefresh-Agent': 'cli',
@@ -65,6 +66,10 @@ async function startCommandLine() {
6566
describe: `Custom path for authentication contexts config file (default: ${DEFAULTS.CFCONFIG})`,
6667
global: false,
6768
})
69+
.option('request-timeout', {
70+
describe: `Request timeout (default: ${cliConfig.request.timeout})`,
71+
global: false,
72+
})
6873
.demandCommand(1, 'You need at least one command before moving on')
6974
.wrap(null)
7075
.version(false)

lib/interface/cli/commands/team/synchronize.cmd.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
const _ = require('lodash');
12
const Command = require('../../Command');
23
const syncRoot = require('../root/synchronize.cmd');
34
const { sdk } = require('../../../../logic');
5+
const cliConfigManager = require('../../../../logic/cli-config/Manager');
6+
const Spinner = require('ora');
7+
8+
const REQUEST_TIMEOUT = 2 * 60 * 1000;
49

510
const command = new Command({
611
command: 'teams [client-name]',
@@ -31,11 +36,22 @@ const command = new Command({
3136
.example('codefresh synchronize teams [client-name] -t [client-type] -tk [accessToken]', 'Synchronize team with group');
3237
},
3338
handler: async (argv) => {
34-
console.log(JSON.stringify(await sdk.teams.synchronizeClientWithGroup({
35-
name: argv['client-name'],
36-
type: argv['client-type'],
37-
access_token: argv['access-token'],
38-
}), null, 2));
39+
const config = cliConfigManager.config();
40+
if (!_.isInteger(argv.requestTimeout) || config.request.timeout < REQUEST_TIMEOUT) {
41+
_.set(sdk, 'config.http.config.timeout', REQUEST_TIMEOUT);
42+
}
43+
const spinner = Spinner().start('Synchronizing...');
44+
let result;
45+
try {
46+
result = await sdk.teams.synchronizeClientWithGroup({
47+
name: argv['client-name'],
48+
type: argv['client-type'],
49+
access_token: argv['access-token'],
50+
});
51+
} finally {
52+
spinner.clear();
53+
}
54+
console.log(JSON.stringify(result, null, 2));
3955
},
4056
});
4157

lib/logic/cli-config/schema.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
"request": {
2323
"type": "object",
2424
"properties": {
25+
"timeout": {
26+
"type": "integer",
27+
"default": 30000,
28+
"description": "Defines request timeout in ms"
29+
},
2530
"maxAttempts": {
2631
"type": "integer",
2732
"default": 10,
@@ -30,7 +35,7 @@
3035
"retryDelay": {
3136
"type": "integer",
3237
"default": 500,
33-
"description": "Defines delay between retries"
38+
"description": "Defines delay between retries in ms"
3439
}
3540
}
3641
},

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codefresh",
3-
"version": "0.19.2",
3+
"version": "0.19.3",
44
"description": "Codefresh command line utility",
55
"main": "index.js",
66
"preferGlobal": true,
@@ -36,8 +36,8 @@
3636
"bluebird": "^3.5.1",
3737
"cf-errors": "^0.1.11",
3838
"chalk": "^1.1.3",
39+
"codefresh-sdk": "^1.0.5",
3940
"cli-progress": "^1.6.1",
40-
"codefresh-sdk": "^1.0.2",
4141
"colors": "^1.1.2",
4242
"columnify": "^1.5.4",
4343
"compare-versions": "^3.4.0",

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -916,10 +916,10 @@ code-point-at@^1.0.0:
916916
version "1.1.0"
917917
resolved "https://registry.yarnpkg.com/code-point-at/-/code-point-at-1.1.0.tgz#0d070b4d043a5bea33a2f1a40e2edb3d9a4ccf77"
918918

919-
codefresh-sdk@^1.0.2:
920-
version "1.0.2"
921-
resolved "https://registry.yarnpkg.com/codefresh-sdk/-/codefresh-sdk-1.0.2.tgz#4d002c08601931b70c2b2695806921f4f7b536c9"
922-
integrity sha512-RqpO7t6ccHnPtOSR50ZPV3isnGAK+QsrBW6jIOR2eehtHMFvDJk0SvPXiyHOWEuAuyObfUnkVdgCEWc76IpxUw==
919+
codefresh-sdk@^1.0.5:
920+
version "1.0.5"
921+
resolved "https://registry.yarnpkg.com/codefresh-sdk/-/codefresh-sdk-1.0.5.tgz#7b1449d8ec66bee555115d74ba58cfccf9e8c803"
922+
integrity sha512-NAfQIWx0YTv2QZm+2dkubYkNusMacsjsMsdF5AqWw6qVrfcB4t+iBmNuYwv7VsKnS26bopx2TC2kgph0WOinig==
923923
dependencies:
924924
bluebird "^3.5.3"
925925
cf-errors "^0.1.11"

0 commit comments

Comments
 (0)