-
Notifications
You must be signed in to change notification settings - Fork 8
/
connector.go
79 lines (67 loc) · 1.71 KB
/
connector.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
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
74
75
76
77
78
79
package connector
import (
"context"
"github.com/luno/workflow"
)
type Status int
var (
StatusUnknown Status = 0
StatusStarted Status = 1
StatusReadTheDocs Status = 2
StatusFollowedTheExample Status = 3
StatusCreatedAFunExample Status = 4
)
func (s Status) String() string {
switch s {
case StatusStarted:
return "Started"
case StatusReadTheDocs:
return "Read the docs"
case StatusFollowedTheExample:
return "Followed the example"
case StatusCreatedAFunExample:
return "Created a fun example"
default:
return "Unknown"
}
}
type GettingStarted struct {
ReadTheDocs string
FollowAnExample string
CreateAFunExample string
}
type Deps struct {
EventStreamer workflow.EventStreamer
RecordStore workflow.RecordStore
TimeoutStore workflow.TimeoutStore
RoleScheduler workflow.RoleScheduler
Connector workflow.ConnectorConstructor
}
func Workflow(d Deps) *workflow.Workflow[GettingStarted, Status] {
builder := workflow.NewBuilder[GettingStarted, Status]("workflow B")
builder.AddConnector(
"my-example-connector",
d.Connector,
func(ctx context.Context, w *workflow.Workflow[GettingStarted, Status], e *workflow.ConnectorEvent) error {
_, err := w.Trigger(ctx, e.ForeignID, StatusStarted, workflow.WithInitialValue[GettingStarted, Status](&GettingStarted{
ReadTheDocs: "✅",
}))
if err != nil {
return err
}
return nil
},
)
builder.AddStep(StatusStarted,
func(ctx context.Context, r *workflow.Run[GettingStarted, Status]) (Status, error) {
r.Object.FollowAnExample = "✅"
return StatusFollowedTheExample, nil
},
StatusFollowedTheExample,
)
return builder.Build(
d.EventStreamer,
d.RecordStore,
d.RoleScheduler,
)
}