-
Notifications
You must be signed in to change notification settings - Fork 169
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(3181): Skip execution of a virtual job when an event is started from that job #3252
feat(3181): Skip execution of a virtual job when an event is started from that job #3252
Conversation
}); | ||
} else if (desiredStatus === 'QUEUED' && currentStatus !== 'QUEUED') { | ||
throw boom.badRequest(`Cannot update builds to ${desiredStatus}`); | ||
} else if (desiredStatus === 'BLOCKED' && currentStatus === 'BLOCKED') { |
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.
making sure that currentStatus === 'BLOCKED'
is what needed here and not currentStatus !== 'BLOCKED'
.
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.
This is an existing code. Just moved it to a common module. Avoiding any additional refactoring/correction as part of this PR.
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.
No change needed. This is an exiting logic. Just moved it to a common module.
Per the comment "Queue-Service can call BLOCKED status update multiple times", both desiredStatus
and currentStatus
can be BLOCKED
.
@@ -244,6 +246,23 @@ module.exports = () => ({ | |||
if (event.builds === null) { | |||
return boom.notFound('No jobs to start.'); | |||
} | |||
|
|||
const virtualJobBuilds = event.builds.filter(b => b.status === 'CREATED'); |
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 that enough to assume that all builds with status === 'CREATED'
is a virtual job then?
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.
Also, shouldn't this be virtualJobBuild
(i.e., singular) as the event is triggered from a single job and there should only be 1 build created for the virtual job?
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.
This could be plural, when we have an event started from ~pr
or ~commit
, and there are more than one virtual job listening to these triggers.
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.
yes, builds created immediately after the event is created would be in CREATED
status only if the job is virtual.
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.
What about builds that are waiting for other joined parent downstream builds to complete? Aren't those builds normally created and then park with "CREATED" status?
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.
There are the builds at the beginning of the workflow for an event. I believe, these wouldn't be waiting for any upstream.
plugins/builds/helper/updateBuild.js
Outdated
/** | ||
* Updates execution details for init step | ||
* @method stopFrozenBuild | ||
* @param {Object} build Build Object | ||
* @param {Object} app Hapi app Object | ||
*/ |
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.
/** | |
* Updates execution details for init step | |
* @method stopFrozenBuild | |
* @param {Object} build Build Object | |
* @param {Object} app Hapi app Object | |
*/ | |
/** | |
* Updates execution details for init step | |
* @method updateInitStep | |
* @param {Object} build Build Object | |
* @param {Object} app Hapi app Object | |
* @return {Promise} Promise resolving when the init step is updated | |
*/ |
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
step.endTime = build.startTime || new Date().toISOString(); | ||
step.code = 0; | ||
|
||
return step.update(); |
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.
return step.update(); | |
return await step.update(); |
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.
Same here we don't to await
here. It is done by the caller
https://github.com/screwdriver-cd/screwdriver/pull/3252/files/d12977ba7d6469c2ca79437eb26f62eb580b3c5b#diff-2c3decb1d714adeb8f265dd68e51a120caa8ada38d91b21d9dffc66974f3276dR206
plugins/builds/helper/updateBuild.js
Outdated
if (currentStatus !== 'UNSTABLE') { | ||
if (desiredStatus !== undefined) { | ||
build.status = desiredStatus; | ||
} | ||
if (build.status === 'ABORTED') { | ||
if (currentStatus === 'FROZEN') { | ||
build.statusMessage = `Frozen build aborted by ${username}`; | ||
} else { | ||
build.statusMessage = `Aborted by ${username}`; | ||
} | ||
} else if (build.status === 'FAILURE' || build.status === 'SUCCESS') { | ||
if (statusMessage) { | ||
build.statusMessage = statusMessage; | ||
build.statusMessageType = statusMessageType || null; | ||
} | ||
} else { | ||
build.statusMessage = statusMessage || null; | ||
build.statusMessageType = statusMessageType || null; | ||
} | ||
} |
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.
if (currentStatus !== 'UNSTABLE') { | |
if (desiredStatus !== undefined) { | |
build.status = desiredStatus; | |
} | |
if (build.status === 'ABORTED') { | |
if (currentStatus === 'FROZEN') { | |
build.statusMessage = `Frozen build aborted by ${username}`; | |
} else { | |
build.statusMessage = `Aborted by ${username}`; | |
} | |
} else if (build.status === 'FAILURE' || build.status === 'SUCCESS') { | |
if (statusMessage) { | |
build.statusMessage = statusMessage; | |
build.statusMessageType = statusMessageType || null; | |
} | |
} else { | |
build.statusMessage = statusMessage || null; | |
build.statusMessageType = statusMessageType || null; | |
} | |
} | |
// UNSTABLE -> SUCCESS needs to update meta and endtime. | |
// However, the status itself cannot be updated to SUCCESS | |
if (currentStatus === 'UNSTABLE') { | |
return; | |
} | |
// Update the build status if desiredStatus is provided | |
if (desiredStatus !== undefined) { | |
build.status = desiredStatus; | |
} | |
// Handle different statuses and set the appropriate status message | |
switch (build.status) { | |
case 'ABORTED': | |
build.statusMessage = currentStatus === 'FROZEN' | |
? `Frozen build aborted by ${username}` | |
: `Aborted by ${username}`; | |
break; | |
case 'FAILURE': | |
case 'SUCCESS': | |
if (statusMessage) { | |
build.statusMessage = statusMessage; | |
build.statusMessageType = statusMessageType || null; | |
} | |
break; | |
default: | |
build.statusMessage = statusMessage || null; | |
build.statusMessageType = statusMessageType || null; | |
break; | |
} |
to improve readability:
- use early return
- use switch instead of nested if else.
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
plugins/builds/helper/updateBuild.js
Outdated
const stageJobIds = stage.jobIds; | ||
|
||
stageJobIds.push(stage.setup); |
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.
const stageJobIds = stage.jobIds; | |
stageJobIds.push(stage.setup); | |
const stageJobIds = [...stage.jobIds, stage.setup]; |
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
test/plugins/events.test.js
Outdated
eventFactoryMock.get.withArgs(parentEventId).resolves(getEventMock(testEvent)); | ||
eventFactoryMock.create.resolves(getEventMock(testEvent)); | ||
eventMock = getEventMock(testEvent); | ||
// eventFactoryMock.get.withArgs(parentEventId).resolves(getEventMock(testEvent)); |
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.
// eventFactoryMock.get.withArgs(parentEventId).resolves(getEventMock(testEvent)); |
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
@@ -244,6 +246,23 @@ module.exports = () => ({ | |||
if (event.builds === null) { | |||
return boom.notFound('No jobs to start.'); | |||
} | |||
|
|||
const virtualJobBuilds = event.builds.filter(b => b.status === 'CREATED'); |
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.
Also, shouldn't this be virtualJobBuild
(i.e., singular) as the event is triggered from a single job and there should only be 1 build created for the virtual job?
Context
Per changes made in screwdriver-cd/models#635, virtual job builds at the beginning in the workflow for an event, may not be queued for execution. Status of such build will be set to
CREATED
.Objective
Identify such build immediately after creating the event to mark its status as 'SUCCESS' and trigger its downstream jobs.
References
#3181
License
I confirm that this contribution is made under a BSD license and that I have the authority necessary to make this contribution on behalf of its copyright owner.