Skip to content

Commit

Permalink
Check Jenkins query exception message
Browse files Browse the repository at this point in the history
Ignore invalid build url when the error is 404

Fixes: adoptium#4

Signed-off-by: lanxia <lan_xia@ca.ibm.com>
  • Loading branch information
llxia committed Aug 30, 2018
1 parent 673e6ba commit d475bff
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
27 changes: 13 additions & 14 deletions TestResultSummaryService/BuildProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,22 @@ class BuildProcessor {
const jenkinsInfo = new JenkinsInfo();
const buildInfo = await jenkinsInfo.getBuildInfo( task.url, task.buildName, task.buildNum );

if ( buildInfo ) {
if ( buildInfo) {
if (buildInfo.code === 404 ){
/*
* Return code is 404. The url is invalid or the build does not
* exist on Jenkins any more, just set status to Done and store
* the build info
*/
task.status = "Done";
await new DataManager().updateBuild( task );
return;
}
let output = "";
if ( task.status === "Streaming" ) {
let startPtr = 0;
//if output exists, get last position from output and continue stream. Otherwise, create build.
// if output exists, get last position from output and continue
// streaming. Otherwise, create build.
if ( task.buildOutputId ) {
const outputDB = new OutputDB();
const result = await outputDB.getData( { _id: new ObjectID( task.buildOutputId ) } ).toArray();
Expand Down Expand Up @@ -88,19 +99,7 @@ class BuildProcessor {
} );
}
}
} else {
/*
if the build does not exist on Jenkins any more, just
set status to Done and store the build info
*/
// TODO: the code can be more precise and check for error
// that is caught in jenkinsInfo.getBuildInfo() to
// determine if it is a build does not exist or connection
// issue.
task.status = "Done";
await new DataManager().updateBuild( task );
}

}
}
module.exports = BuildProcessor;
5 changes: 4 additions & 1 deletion TestResultSummaryService/JenkinsInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { logger } = require( './Utils' );

const options = { request: { timeout: 2000 } };

//Server connection may drop. If timeout, retry.
// Server connection may drop. If timeout, retry.
const retry = fn => {
const promise = Promise.promisify( fn );
return async function() {
Expand All @@ -14,6 +14,9 @@ const retry = fn => {
} catch ( e ) {
logger.warn( `Try #${i + 1}: connection issue`, arguments );
logger.warn( e );
if (e.toString().includes ("unexpected status code: 404")) {
return {code: 404};
}
}
}
}
Expand Down

0 comments on commit d475bff

Please sign in to comment.