-
Notifications
You must be signed in to change notification settings - Fork 158
/
main.go
70 lines (56 loc) · 1.31 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
69
70
package main
import (
"fmt"
"github.com/joho/godotenv"
"github.com/hatchet-dev/hatchet/pkg/client"
"github.com/hatchet-dev/hatchet/pkg/cmdutils"
"github.com/hatchet-dev/hatchet/pkg/worker"
)
type stepOutput struct{}
func main() {
err := godotenv.Load()
if err != nil {
panic(err)
}
c, err := client.New()
if err != nil {
panic(fmt.Sprintf("error creating client: %v", err))
}
w, err := worker.NewWorker(
worker.WithClient(
c,
),
worker.WithMaxRuns(1),
)
if err != nil {
panic(fmt.Sprintf("error creating worker: %v", err))
}
testSvc := w.NewService("test")
err = testSvc.On(
worker.Events("simple"),
&worker.WorkflowJob{
Name: "simple-workflow",
Description: "Simple one-step workflow.",
Steps: []*worker.WorkflowStep{
worker.Fn(func(ctx worker.HatchetContext) (result *stepOutput, err error) {
fmt.Println("executed step 1")
return &stepOutput{}, nil
},
).SetName("step-one"),
},
},
)
if err != nil {
panic(fmt.Sprintf("error registering workflow: %v", err))
}
interruptCtx, cancel := cmdutils.InterruptContextFromChan(cmdutils.InterruptChan())
defer cancel()
cleanup, err := w.Start()
if err != nil {
panic(fmt.Sprintf("error starting worker: %v", err))
}
<-interruptCtx.Done()
if err := cleanup(); err != nil {
panic(err)
}
}