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

feat(3209): Skip execution of virtual job and mark it as SUCCESS #76

Merged
merged 2 commits into from
Oct 4, 2024

Conversation

sagar1312
Copy link
Member

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.

@sagar1312 sagar1312 force-pushed the sagar1312-fix-3209-skip_execution_of_virtual_job branch from 29c258d to 90b2cf7 Compare October 3, 2024 16:01
@sagar1312 sagar1312 force-pushed the sagar1312-fix-3209-skip_execution_of_virtual_job branch from 90b2cf7 to 315328b Compare October 3, 2024 16:18
* @return {Boolean}
*/
function isVirtualJob(annotations) {
return annotations && annotations['screwdriver.cd/virtualJob'];
Copy link
Member

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Boolean

Comment on lines 432 to 446
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;
});
Copy link
Member

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;
    });

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@VonnyJap VonnyJap merged commit 8c8486f into master Oct 4, 2024
2 checks passed
@VonnyJap VonnyJap deleted the sagar1312-fix-3209-skip_execution_of_virtual_job branch October 4, 2024 20:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants