-
Notifications
You must be signed in to change notification settings - Fork 158
/
main.go
75 lines (61 loc) · 1.28 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
71
72
73
74
75
package main
import (
"context"
"fmt"
"time"
"github.com/hatchet-dev/hatchet/pkg/client"
"github.com/hatchet-dev/hatchet/pkg/cmdutils"
"github.com/joho/godotenv"
)
type Event struct {
ID uint64 `json:"id"`
CreatedAt time.Time `json:"created_at"`
}
type stepOneOutput struct {
Message string `json:"message"`
}
func StepOne(ctx context.Context, input *Event) (result *stepOneOutput, err error) {
fmt.Println(input.ID, "delay", time.Since(input.CreatedAt))
return &stepOneOutput{
Message: "This ran at: " + time.Now().Format(time.RubyDate),
}, nil
}
func main() {
err := godotenv.Load()
if err != nil {
panic(err)
}
client, err := client.New()
if err != nil {
panic(err)
}
interruptCtx, cancel := cmdutils.InterruptContextFromChan(cmdutils.InterruptChan())
defer cancel()
var id uint64
go func() {
for {
select {
case <-time.After(5 * time.Second):
for i := 0; i < 100; i++ {
id++
ev := Event{CreatedAt: time.Now(), ID: id}
fmt.Println("pushed event", ev.ID)
err = client.Event().Push(interruptCtx, "test:event", ev)
if err != nil {
panic(err)
}
}
case <-interruptCtx.Done():
return
}
}
}()
for {
select {
case <-interruptCtx.Done():
return
default:
time.Sleep(time.Second)
}
}
}