-
Notifications
You must be signed in to change notification settings - Fork 202
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
update cancellation sample #276
base: main
Are you sure you want to change the base?
Conversation
cancellation/activity.go
Outdated
@@ -21,7 +21,7 @@ func (a *Activities) ActivityToBeCanceled(ctx context.Context) (string, error) { | |||
activity.RecordHeartbeat(ctx, "") | |||
case <-ctx.Done(): | |||
logger.Info("context is cancelled") | |||
return "I am canceled by Done", nil | |||
return "I am canceled by Done", ctx.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.
No reason to return a value if you're returning cancellation
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 :)
cancellation/workflow.go
Outdated
}() | ||
|
||
var result string | ||
err := workflow.ExecuteActivity(ctx, a.ActivityToBeCanceled).Get(ctx, &result) | ||
if err != nil { | ||
return err | ||
} | ||
logger.Info(fmt.Sprintf("ActivityToBeCanceled returns %v, %v", result, 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.
No reason to log an error you know is nil
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 :)
cancellation/workflow.go
Outdated
err = workflow.ExecuteActivity(ctx, a.ActivityToBeSkipped).Get(ctx, nil) | ||
logger.Error("Error from ActivityToBeSkipped", "Error", 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.
The original purpose of this sample was to show that this is skipped because the context is already cancelled. Now that we return early unlike before, this is essentially unreachable code. Do you want to remove it?
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, also added cleanup activity specific activity options (as it can fail heartbeat timeout, and its not heartbeating anyways)
Signed-off-by: Tihomir Surdilovic <[email protected]>
Signed-off-by: Tihomir Surdilovic <[email protected]>
Signed-off-by: Tihomir Surdilovic <[email protected]>
a33890b
to
2429adb
Compare
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.
May want @Quinn-With-Two-Ns to take a peek also
logger.Error("Error from ActivityToBeSkipped", "Error", err) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
logger.Info("Workflow Execution complete.") |
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.
Unreachable code, but in this case I think it's fine
@tsurdilo did you want to merge this? |
Updates cancellation sample: