forked from temporalio/samples-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
activity.go
41 lines (34 loc) · 1.04 KB
/
activity.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package cancellation
import (
"context"
"time"
"go.temporal.io/sdk/activity"
)
// @@@SNIPSTART samples-go-cancellation-activity-definition
type Activities struct{}
func (a *Activities) ActivityToBeCanceled(ctx context.Context) (string, error) {
logger := activity.GetLogger(ctx)
logger.Info("activity started, to cancel the Workflow Execution, use 'go run cancellation/cancel/main.go " +
"-w <WorkflowID>' or use the CLI: 'tctl wf cancel -w <WorkflowID>'")
for {
select {
case <-time.After(1 * time.Second):
logger.Info("heartbeating...")
activity.RecordHeartbeat(ctx, "")
case <-ctx.Done():
logger.Info("context is cancelled")
return "I am canceled by Done", nil
}
}
}
func (a *Activities) CleanupActivity(ctx context.Context) error {
logger := activity.GetLogger(ctx)
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