-
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
feat(3209): Skip execution of virtual job and mark it as SUCCESS #76
Conversation
29c258d
to
90b2cf7
Compare
90b2cf7
to
315328b
Compare
* @return {Boolean} | ||
*/ | ||
function isVirtualJob(annotations) { | ||
return annotations && annotations['screwdriver.cd/virtualJob']; |
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
plugins/queue/scheduler.js
Outdated
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Can we abstract this section out, the same helper.updateBuild
is called in either conditions just with different payload
. Prefer this to be cleaner.
let payload;
if (isVirtualJob(annotations)) {
// Bypass execution of the build if the job is virtual
payload = {
status: 'SUCCESS',
statusMessage: 'Skipped execution of the virtual job'
};
} 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) {
payload = { stats: build.stats, status: 'QUEUED' };
}
}
await helper
.updateBuild(
{
buildId,
token: buildToken,
apiUri,
payload
},
helper.requestRetryStrategy
)
.catch(err => {
if (isVirtualJob(annotations)) {
logger.error(`virtualBuilds: failed to update build status for build ${buildId}: ${err}`);
} else {
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.
Done
Context
screwdriver-cd/screwdriver#3027
A job can be marked as virtual by adding the annotation
screwdriver.cd/virtualJob: true
. Such jobs should not be executed.Objective
Builds added to the queue for virtual jobs should skip the execution.
Status of builds of such jobs should be updated to "SUCCESS".
References
screwdriver-cd/screwdriver#3209
License
I confirm that this contribution is made under the terms of the license found in the root directory of this repository's source tree and that I have the authority necessary to make this contribution on behalf of its copyright owner.