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

[POC] Show a way to implement cancellable updates #297

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Quinn-With-Two-Ns
Copy link
Contributor

Show how one could implement cancellable updates purely in user side code.

@@ -4,6 +4,9 @@ go 1.16

replace github.com/cactus/go-statsd-client => github.com/cactus/go-statsd-client v3.2.1+incompatible

replace (
go.temporal.io/sdk v1.23.1 => ../sdk-go
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Update interceptors don't work on the current release of the Go SDK

@Quinn-With-Two-Ns Quinn-With-Two-Ns changed the title Show a way to implement cancellable updates [POC] Show a way to implement cancellable updates Jul 18, 2023
Copy link
Member

Choose a reason for hiding this comment

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

Hrmm, not sure this is a pattern we should encourage, especially hiding this logic in an interceptor. I think it may be clearer if we should how to cancel an update context from another update explicitly in workflow code. If they want to make that generic to apply to all updates hidden away in an interceptor, then they can.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason I moved it into the interceptor is to show you don't need to explicitly add support in your workflow

Copy link
Member

@cretz cretz Jul 18, 2023

Choose a reason for hiding this comment

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

Right, but I don't think we should encourage interceptors like this nor provide a general purpose utility. I think we should show a simple example how you can cancel a single update and if someone wants to go the extra step of hiding this from workflow authors, they can.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it just makes the code a less elegant to do it in the workflow, but for the samples repo your right we shouldn't encourage usage of interceptors like this

Copy link
Member

@cretz cretz Jul 18, 2023

Choose a reason for hiding this comment

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

Definitely less elegant and less reusable. Acknowledged. Kinda on purpose, which is admittedly a bit strange, but we don't want people to blindly copy the approach. What I've found is that many times people want to customize these patterns so seeing them in-workflow is easy to understand.

And really, if we wanted to write this properly for reuse, I might recommend a utility instead of an interceptor.

func (w *workflowInboundInterceptor) ExecuteWorkflow(ctx workflow.Context, in *interceptor.ExecuteWorkflowInput) (interface{}, error) {
err := workflow.SetUpdateHandlerWithOptions(ctx, UpdateCancelHandle, func(ctx workflow.Context, updateID string) error {
// Cancel the update
w.ctxMap[updateID]()
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably want to delete from ctxMap here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't delete because I wanted duplicate cancels to behave the same as the server, but I didn't implement that behaviour yet

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.

3 participants