-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworker.go
More file actions
73 lines (64 loc) · 1.59 KB
/
Copy pathworker.go
File metadata and controls
73 lines (64 loc) · 1.59 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Package main shows an example Temporal worker registering the drain workflow options
package main
import (
"context"
"fmt"
"time"
"github.com/kevindweb/version-drain/pkg/drain"
"go.temporal.io/api/enums/v1"
"go.temporal.io/sdk/client"
"go.temporal.io/sdk/worker"
)
const (
// compatibilityVersion represents the version your team will "bump"
// to keep Temporal clients and workers assigning work on the correct queue
compatibilityVersion = "1.0"
)
func newClient() client.Client {
c, err := client.NewLazyClient(client.Options{})
if err != nil {
panic(err)
}
return c
}
func setup() {
c := newClient()
queue := "example-queue"
w := worker.New(c, queue, options())
config := drain.Config{
Temporal: c,
Namespace: "example-ns",
}
if err := drain.Register(w, config); err != nil {
panic(err)
}
}
func options() worker.Options {
return worker.Options{
BuildID: compatibilityVersion,
UseBuildIDForVersioning: true,
}
}
func versionBump(version, queue string) {
wf := "ExampleContinueWorkflow"
workflowOptions := client.StartWorkflowOptions{
WorkflowIDReusePolicy: enums.WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE,
ID: fmt.Sprintf("migrate-%s-%s", wf, version),
TaskQueue: queue,
}
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()
init := drain.VersionDrainIn{
Queue: queue,
WorkflowType: wf,
Version: version,
}
if _, err := newClient().ExecuteWorkflow(
ctx, workflowOptions, drain.QueueDrainWorkflow, init,
); err != nil {
panic(err)
}
}
func main() {
setup()
}