-
Notifications
You must be signed in to change notification settings - Fork 182
Fix cancel handling in pipedv1 scheduler #5597
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
Changes from 2 commits
c4b65dc
9a27453
a755ab8
4d96f03
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 | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -455,9 +455,8 @@ type ExecuteStageResponse struct { | |||||||||||||||||||||||||
type StageStatus int | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
const ( | ||||||||||||||||||||||||||
StageStatusSuccess StageStatus = 2 | ||||||||||||||||||||||||||
StageStatusFailure StageStatus = 3 | ||||||||||||||||||||||||||
StageStatusCancelled StageStatus = 4 | ||||||||||||||||||||||||||
StageStatusSuccess StageStatus = 2 | ||||||||||||||||||||||||||
StageStatusFailure StageStatus = 3 | ||||||||||||||||||||||||||
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. [Q] I don't remember why we made this enum start from 2; could you teach me? 👀 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. Because these lines are copied from below. It's a bit confusing, so I want to make them start from 1. pipecd/pkg/model/deployment.pb.go Lines 109 to 120 in ad00a56
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. I refactored it on this commit. |
||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
// StageStatusSkipped StageStatus = 5 // TODO: If SDK can handle whole skipping, this is unnecessary. | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
|
@@ -472,8 +471,6 @@ func (o StageStatus) toModelEnum() model.StageStatus { | |||||||||||||||||||||||||
return model.StageStatus_STAGE_SUCCESS | ||||||||||||||||||||||||||
case StageStatusFailure: | ||||||||||||||||||||||||||
return model.StageStatus_STAGE_FAILURE | ||||||||||||||||||||||||||
case StageStatusCancelled: | ||||||||||||||||||||||||||
return model.StageStatus_STAGE_CANCELLED | ||||||||||||||||||||||||||
case StageStatusExited: | ||||||||||||||||||||||||||
return model.StageStatus_STAGE_EXITED | ||||||||||||||||||||||||||
default: | ||||||||||||||||||||||||||
|
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.
[IMO] I think
StageStatusCancelled
should remain, although it's not used in piped.That's because plugin developers will be confused about which status to return.
If we want to remove
StageStatusCancelled
, we should removecase <-ctx.Done():
section too. (If possible, that's ideal)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.
I see what you are concerned about.
On the other hand, my concern is that the plugin developers may think they have to handle context cancellation as StageStatusCancelled. This is incorrect; the plugin should exit its operation on the context cancel without concern about its response.
The WAIT plugin's case is special because we must handle context cancellation to exit its operation. Almost all plugins can do this only by passing the context to their internal functions because deployment operations can handle context cancellation as a failure.
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.
I agree!
What about WaitApproval and ScriptRun stages?
pipecd/pkg/app/piped/executor/waitapproval/waitapproval.go
Lines 67 to 88 in ad00a56
pipecd/pkg/app/piped/executor/scriptrun/scriptrun.go
Lines 71 to 92 in ad00a56
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.
First, the timeout should be handled on the piped side so the plugin doesn't have to.
SCRIPT_RUN stage should use os/exec.CommandContext: it handles context cancellation as an interruption of executed commands. So we can implement it without watching ctx.Done().
WAIT_APPROVAL stage is difficult to implement without watching ctx.Done() because it doesn't operate something with context other than polling the approval states.
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.
ok, i got it.
Let's add a note about when to handle
ctx.Done()
to the plugin dev guide.Even if
StageStatusCancelled
is removed, plugin developers should be aware of cancellation to certainly exit the stage.