Skip to content

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
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 :)

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)

tsurdilo added 3 commits May 12, 2023 10:06
Signed-off-by: Tihomir Surdilovic <[email protected]>
Signed-off-by: Tihomir Surdilovic <[email protected]>
Signed-off-by: Tihomir Surdilovic <[email protected]>
@tsurdilo tsurdilo force-pushed the upcancellationsample branch from a33890b to 2429adb Compare May 12, 2023 14:06
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

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.

4 participants