-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
45 lines (35 loc) · 902 Bytes
/
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
package main
import (
"context"
"fmt"
"log"
"time"
"github.com/matroskin13/stepper"
mongoEngine "github.com/matroskin13/stepper/engines/mongo"
"github.com/matroskin13/stepper/examples"
"github.com/matroskin13/stepper/middlewares"
)
type State struct {
Count int
}
func main() {
db, err := examples.CreateMongoDatabase("stepepr")
if err != nil {
log.Fatal(err)
}
e := mongoEngine.NewMongoWithDb(db)
s := stepper.NewService(e)
s.UseMiddleware(middlewares.LogMiddleware())
s.TaskHandler("simple", func(ctx stepper.Context, data []byte) error {
fmt.Println(string(data))
return nil
})
for i := 0; i < 10; i++ {
if err := s.Publish(context.Background(), "simple", []byte(fmt.Sprintf("hello from %v", i)), stepper.LaunchAt(time.Now().Add(time.Second*3))); err != nil {
log.Fatal(err)
}
}
if err := s.Listen(context.Background()); err != nil {
log.Fatal(err)
}
}