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

Update build retry logic #858

Merged
merged 1 commit into from
Mar 27, 2024
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
9 changes: 8 additions & 1 deletion TestResultSummaryService/DataManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,14 @@ class DataManager {
}

async updateBuild(data) {
logger.verbose('updateBuild', data.buildName, data.buildNum);
if (data.buildUrl) {
logger.verbose('updateBuild', data.buildUrl);
} else if (data.buildName) {
logger.verbose('updateBuild', data.buildName, data.buildNum);
} else {
logger.verbose('updateBuild', data._id);
}

const { _id, buildName, ...newData } = data;
const criteria = { _id: new ObjectID(_id) };
const testResults = new TestResultsDB();
Expand Down
30 changes: 20 additions & 10 deletions TestResultSummaryService/JenkinsInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,31 @@ const options = { request: { timeout: 30000 } };

// Server connection may drop. If timeout, retry.
const retry = (fn) => {
const promise = Promise.promisify(fn);
return async function () {
for (let i = 0; i < 3; i++) {
try {
return await promise.apply(null, arguments);
return await new Promise((resolve, reject) => {
fn(...arguments, (err, data) => {
if (err) {
logger.warn(err);
reject(data);
} else {
resolve(data);
}
});
});
} catch (e) {
logger.warn(`Try #${i + 1}: connection issue`, arguments);
logger.warn(e);
logger.warn(`Sleep 2 secs...`);
await Promise.delay(2 * 1000);
if (
i === 2 &&
e.toString().includes('unexpected status code: 404')
) {
return { code: 404 };
if (e) {
logger.warn(`status code: ${e.statusCode}`);
logger.warn(`headers: ${JSON.stringify(e.headers)}`);

// return code 404 only if the Jenkins server returns 404 for the build (i.e., invalid url, expired build, etc)
// x-jenkins header is checked to ensure the error code is from Jenkins (not nginx)
// TRSS will stop processing this build once code 404 is returned. See BuildProcessor for details.
if (e.statusCode === 404 && e.headers['x-jenkins']) {
return { code: e.statusCode };
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions TestResultSummaryService/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ app.get('/getData', wrap(require('./getData')));
app.get('/getErrorInOutput', wrap(require('./getErrorInOutput')));
app.get('/getHistoryPerTest', wrap(require('./getHistoryPerTest')));
app.get('/getJenkins', wrap(require('./getJenkins')));
app.get('/getJenkinsBuildInfo', wrap(require('./test/getJenkinsBuildInfo')));
app.get('/getLastBuildInfo', wrap(require('./getLastBuildInfo')));
app.get('/getLogStream', wrap(require('./getLogStream')));
app.get('/getOutputById', wrap(require('./getOutputById')));
Expand Down
14 changes: 14 additions & 0 deletions TestResultSummaryService/routes/test/getJenkinsBuildInfo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const JenkinsInfo = require('../../JenkinsInfo');

module.exports = async (req, res) => {
const { url, buildName, buildNum } = req.query;
if (req.query.buildNum)
req.query.buildNum = parseInt(req.query.buildNum, 10);
const jenkinsInfo = new JenkinsInfo();
try {
const output = await jenkinsInfo.getBuildInfo(url, buildName, buildNum);
res.send({ output });
} catch (e) {
res.send({ result: e.toString() });
}
};
Loading