Skip to content

Commit

Permalink
updated sample
Browse files Browse the repository at this point in the history
Signed-off-by: Tihomir Surdilovic <tihomir@temporal.io>
  • Loading branch information
tsurdilo committed May 12, 2023
1 parent 30cac9d commit 2429adb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
7 changes: 0 additions & 7 deletions cancellation/activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,4 @@ func (a *Activities) CleanupActivity(ctx context.Context) error {
logger.Info("Cleanup Activity started")
return nil
}

func (a *Activities) ActivityToBeSkipped(ctx context.Context) error {
logger := activity.GetLogger(ctx)
logger.Info("this Activity will be skipped due to cancellation")
return nil
}

// @@@SNIPEND
9 changes: 5 additions & 4 deletions cancellation/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ func YourWorkflow(ctx workflow.Context) error {
}

// When the Workflow is canceled, it has to get a new disconnected context to execute any Activities
// Specify activity options for cleanup activity
aoCleanup := workflow.ActivityOptions{
StartToCloseTimeout: 2 * time.Second,
}
newCtx, _ := workflow.NewDisconnectedContext(ctx)
newCtx = workflow.WithActivityOptions(newCtx, aoCleanup)
err := workflow.ExecuteActivity(newCtx, a.CleanupActivity).Get(ctx, nil)
if err != nil {
logger.Error("CleanupActivity failed", "Error", err)
Expand All @@ -39,10 +44,6 @@ func YourWorkflow(ctx workflow.Context) error {
return err
}

err = workflow.ExecuteActivity(ctx, a.ActivityToBeSkipped).Get(ctx, nil)
logger.Error("Error from ActivityToBeSkipped", "Error", err)

logger.Info("Workflow Execution complete.")

return nil
}

0 comments on commit 2429adb

Please sign in to comment.