-
Notifications
You must be signed in to change notification settings - Fork 5
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
feat(3209): Skip execution of virtual job and mark it as SUCCESS #76
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,16 @@ const TEMPORAL_TOKEN_TIMEOUT = 12 * 60; // 12 hours in minutes | |
const TEMPORAL_UNZIP_TOKEN_TIMEOUT = 2 * 60; // 2 hours in minutes | ||
const BLOCKED_BY_SAME_JOB_WAIT_TIME = 5; | ||
|
||
/** | ||
* Checks whether the job associated with the build is virtual or not | ||
* @method isVirtualJob | ||
* @param {Object} annotations Job Annotations | ||
* @return {Boolean} | ||
*/ | ||
function isVirtualJob(annotations) { | ||
return annotations && annotations['screwdriver.cd/virtualJob']; | ||
} | ||
|
||
/** | ||
* Posts a new build event to the API | ||
* @method postBuildEvent | ||
|
@@ -300,7 +310,8 @@ async function start(executor, config) { | |
apiUri, | ||
pipeline, | ||
isPR, | ||
prParentJobId | ||
prParentJobId, | ||
annotations | ||
} = config; | ||
const forceStart = /\[(force start)\]/.test(causeMessage); | ||
|
||
|
@@ -411,48 +422,75 @@ async function start(executor, config) { | |
throw value.error; | ||
} | ||
|
||
const token = executor.tokenGen(Object.assign(tokenConfig, { scope: ['temporal'] }), TEMPORAL_TOKEN_TIMEOUT); | ||
|
||
// set the start time in the queue | ||
Object.assign(config, { token }); | ||
// Store the config in redis | ||
await executor.redisBreaker.runCommand('hset', executor.buildConfigTable, buildId, JSON.stringify(config)); | ||
|
||
const blockedBySameJob = reach(config, 'annotations>screwdriver.cd/blockedBySameJob', { | ||
separator: '>', | ||
default: true | ||
}); | ||
const blockedBySameJobWaitTime = reach(config, 'annotations>screwdriver.cd/blockedBySameJobWaitTime', { | ||
separator: '>', | ||
default: BLOCKED_BY_SAME_JOB_WAIT_TIME | ||
}); | ||
if (isVirtualJob(annotations)) { | ||
// Bypass execution of the build if the job is virtual | ||
const payload = { | ||
status: 'SUCCESS', | ||
statusMessage: 'Skipped execution of the virtual job' | ||
}; | ||
|
||
// Note: arguments to enqueue are [queue name, job name, array of args] | ||
enq = await executor.queueBreaker.runCommand('enqueue', executor.buildQueue, 'start', [ | ||
{ | ||
buildId, | ||
jobId, | ||
blockedBy: blockedBy.toString(), | ||
blockedBySameJob, | ||
blockedBySameJobWaitTime | ||
} | ||
]); | ||
if (buildStats) { | ||
await helper | ||
.updateBuild( | ||
{ | ||
buildId, | ||
token: buildToken, | ||
apiUri, | ||
payload: { stats: build.stats, status: 'QUEUED' } | ||
payload | ||
}, | ||
helper.requestRetryStrategy | ||
) | ||
.catch(err => { | ||
logger.error(`Failed to update build status for build ${buildId}: ${err}`); | ||
logger.error(`virtualBuilds: failed to update build status for build ${buildId}: ${err}`); | ||
|
||
throw err; | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we abstract this section out, the same
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
} else { | ||
const token = executor.tokenGen( | ||
Object.assign(tokenConfig, { scope: ['temporal'] }), | ||
TEMPORAL_TOKEN_TIMEOUT | ||
); | ||
|
||
// set the start time in the queue | ||
Object.assign(config, { token }); | ||
// Store the config in redis | ||
await executor.redisBreaker.runCommand('hset', executor.buildConfigTable, buildId, JSON.stringify(config)); | ||
|
||
const blockedBySameJob = reach(config, 'annotations>screwdriver.cd/blockedBySameJob', { | ||
separator: '>', | ||
default: true | ||
}); | ||
const blockedBySameJobWaitTime = reach(config, 'annotations>screwdriver.cd/blockedBySameJobWaitTime', { | ||
separator: '>', | ||
default: BLOCKED_BY_SAME_JOB_WAIT_TIME | ||
}); | ||
|
||
// Note: arguments to enqueue are [queue name, job name, array of args] | ||
enq = await executor.queueBreaker.runCommand('enqueue', executor.buildQueue, 'start', [ | ||
{ | ||
buildId, | ||
jobId, | ||
blockedBy: blockedBy.toString(), | ||
blockedBySameJob, | ||
blockedBySameJobWaitTime | ||
} | ||
]); | ||
if (buildStats) { | ||
await helper | ||
.updateBuild( | ||
{ | ||
buildId, | ||
token: buildToken, | ||
apiUri, | ||
payload: { stats: build.stats, status: 'QUEUED' } | ||
}, | ||
helper.requestRetryStrategy | ||
) | ||
.catch(err => { | ||
logger.error(`Failed to update build status for build ${buildId}: ${err}`); | ||
|
||
throw err; | ||
}); | ||
} | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this annotation treated as a boolean or string ? If string you might have to check explicitly the expected value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Boolean