There is example with workflow.NewDisconnectedContext(ctx)
, which used for cleanup activities.
I have a question: it’s possible to cancel disconnected context?
I see that workflow.NewDisconnectedContext(ctx)
return cancellation func at the second, but when i try to call cancellation func activity retry-execution continues.
Code from example before (i edit only defer block)
defer func() {
if !errors.Is(ctx.Err(), workflow.ErrCanceled) {
return
}
// When the Workflow is canceled, it has to get a new disconnected context to execute any Activities
newCtx, cancel := workflow.NewDisconnectedContext(ctx)
go func() {
t := time.NewTimer(1 * time.Second)
select {
case <-t.C:
cancel()
}
}()
err := workflow.ExecuteActivity(newCtx, a.CleanupActivity).Get(newCtx, nil)
if err != nil {
logger.Error("CleanupActivity failed", "Error", err)
}
}()
CleanupActivity
func (a *Activities) CleanupActivity(ctx context.Context) error {
logger := activity.GetLogger(ctx)
logger.Info("Cleanup Activity started")
return fmt.Errorf("any activity err")
}