I’ve been reading @maxim 's articles 1 & 2 on how to implement a cleanup() method when a cancellation occurs but I’m stuck. The documentation (too many links for a new user) seems to only talk about passing that cancellation to the activity which is different from what I want.
The pseudo code what I’m trying to do is something like this:
func MyWorkflow(ctx workflow.Context, request MyWorkflowRequest) error {
// Register signal channels
// ...
// Related workflows
relatedWorkflowIds := []string{
//...
}
// Handle cancellation from this point forward, anywhere in the workflow
go func(ctx workflow.Context) {
for {
select {
case <-ctx.Done():
// Cascade cancellation to related workflows
fmt.Println("Context cancelled:", ctx.Err())
newCtx, _ := workflow.NewDisconnectedContext(ctx)
client, err := clients.NewClient()
for _, workflowId := range relatedWorkflowIds {
err = client.CancelWorkflow(newCtx.Background(), workflowId, "")
if err != nil {
log.Fatalln("Unable to cancel Workflow Execution", err)
}
}
return
}
}
}(ctx)
// Do some activities
// sleep for set period
// Do some more activities
return nil
}
This doesn’t seem to work because of something @maxim said about the context is not the same as the go-lang’s standard context I think.