-
Notifications
You must be signed in to change notification settings - Fork 126
/
main.go
60 lines (45 loc) · 1.12 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
package main
import (
"context"
"fmt"
"github.com/hatchet-dev/hatchet/pkg/client"
"github.com/hatchet-dev/hatchet/pkg/cmdutils"
"github.com/hatchet-dev/hatchet/pkg/worker"
"github.com/joho/godotenv"
)
type printInput struct{}
func main() {
err := godotenv.Load()
if err != nil {
panic(err)
}
client, err := client.New(
client.InitWorkflows(),
)
if err != nil {
panic(err)
}
// Create a worker. This automatically reads in a TemporalClient from .env and workflow files from the .hatchet
// directory, but this can be customized with the `worker.WithTemporalClient` and `worker.WithWorkflowFiles` options.
worker, err := worker.NewWorker(
worker.WithClient(
client,
),
)
if err != nil {
panic(err)
}
err = worker.RegisterAction("print:print", func(ctx context.Context, input *printInput) (result any, err error) {
fmt.Println("called print:print")
return map[string]interface{}{}, nil
})
if err != nil {
panic(err)
}
interruptCtx, cancel := cmdutils.InterruptContextFromChan(cmdutils.InterruptChan())
defer cancel()
err = worker.Start(interruptCtx)
if err != nil {
panic(err)
}
}