Skip to content

Commit 037e31e

Browse files
committed
partial code for polling
1 parent d905fcb commit 037e31e

File tree

2 files changed

+51
-11
lines changed

2 files changed

+51
-11
lines changed

bin/helpers/sync/syncSpecsLogs.js

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,57 @@ const request = require('request'),
66

77
let printSpecsStatus = (bsConfig, buildId) => {
88
new Promise((resolve, reject) => {
9-
let backOffFactor = 3; // 3 seconds
10-
let options = {
11-
url: `${config.buildUrl}${buildId}`,
12-
auth: {
13-
user: bsConfig.auth.username,
14-
password: bsConfig.auth.access_key
15-
},
16-
headers: {
17-
'Content-Type': 'application/json',
18-
"User-Agent": utils.getUserAgent(),
9+
poll(data, 2000, 10000).then(resolve(data));
10+
});
11+
}
12+
13+
let poll = (interval, timeout) => {
14+
data = []
15+
16+
return pollRecursive()
17+
.timeout(timeout)
18+
.catch(Promise.TimeoutError, function () {
19+
return false;
20+
});
21+
}
22+
23+
let pollRecursive = () => {
24+
return signal() ? Promise.resolve(true) : Promise.delay(interval).then(pollRecursive);
25+
}
26+
27+
let makeReqest = () => {
28+
let backOffFactor = 3; // 3 seconds
29+
let options = {
30+
url: `${config.buildUrl}${buildId}`,
31+
auth: {
32+
user: bsConfig.auth.username,
33+
password: bsConfig.auth.access_key
34+
},
35+
headers: {
36+
'Content-Type': 'application/json',
37+
"User-Agent": utils.getUserAgent(),
38+
}
39+
}
40+
request.post(options, function (err, resp, body) {
41+
if (err) {
42+
reject(err);
43+
} else {
44+
try {
45+
data = JSON.parse(body);
46+
} catch (error) {
47+
data = null;
1948
}
49+
if (resp.statusCode != 202) {
50+
if (data) {
51+
reject(`${Constants.userMessages.BUILD_FAILED} Error: ${build.message}`);
52+
} else {
53+
reject(Constants.userMessages.BUILD_FAILED);
54+
}
55+
} else {
56+
resolve(build);
57+
}
58+
resolve(build);
59+
2060
}
2161
});
2262
}

bin/helpers/syncRunner.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const Config = require("./config"),
1212

1313
exports.pollBuildStatus = (bsConfig, buildDetails) => {
1414
logBuildDetails(bsConfig, buildDetails);
15-
printSpecsStatus().then((data) => {
15+
syncSpecsLogs.printSpecsStatus(bsConfig, buildDetails).then((data) => {
1616
return specsSummary.printSpecsRunSummary(data.specs, data.time, data.machines);
1717
}).then((data) => {
1818
return specDetails.failedSpecsDetails(data);

0 commit comments

Comments
 (0)