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

update cancellation sample #276

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

update cancellation sample #276

wants to merge 3 commits into from

Conversation

tsurdilo
Copy link
Contributor

@tsurdilo tsurdilo commented May 11, 2023

Updates cancellation sample:

  1. don't swallow error from activity
  2. don't swallow error in activity code since activity options define WaitForCancellation: true

@tsurdilo tsurdilo changed the title update cancelation sample update cancellation sample May 11, 2023
@@ -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()
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done :)

}()

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))
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done :)

Comment on lines 42 to 43
err = workflow.ExecuteActivity(ctx, a.ActivityToBeSkipped).Get(ctx, nil)
logger.Error("Error from ActivityToBeSkipped", "Error", err)
Copy link
Member

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?

Copy link
Contributor Author

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]>
Copy link
Member

@cretz cretz left a 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.")
Copy link
Member

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

@Quinn-With-Two-Ns
Copy link
Contributor

@tsurdilo did you want to merge this?

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.

None yet

3 participants