-
Notifications
You must be signed in to change notification settings - Fork 126
/
main.go
68 lines (52 loc) · 1.26 KB
/
main.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
package main
import (
"fmt"
"time"
"github.com/joho/godotenv"
"github.com/hatchet-dev/hatchet/pkg/client"
"github.com/hatchet-dev/hatchet/pkg/cmdutils"
)
type userCreateEvent struct {
Username string `json:"username"`
UserID string `json:"user_id"`
Data map[string]string `json:"data"`
}
func main() {
err := godotenv.Load()
if err != nil {
panic(err)
}
events := make(chan string, 50)
if err := run(cmdutils.InterruptChan(), events); err != nil {
panic(err)
}
}
func run(ch <-chan interface{}, events chan<- string) error {
c, err := client.New()
if err != nil {
return fmt.Errorf("error creating client: %w", err)
}
time.Sleep(1 * time.Second)
// trigger workflow
workflowRunId, err := c.Admin().RunWorkflow(
"post-user-update",
&userCreateEvent{
Username: "echo-test",
UserID: "1234",
Data: map[string]string{
"test": "test",
},
},
)
if err != nil {
return fmt.Errorf("error running workflow: %w", err)
}
fmt.Println("workflow run id:", workflowRunId)
interruptCtx, cancel := cmdutils.InterruptContextFromChan(ch)
defer cancel()
err = c.Subscribe().On(interruptCtx, workflowRunId, func(event client.RunEvent) error {
fmt.Println(event.EventPayload)
return nil
})
return err
}