-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimpleWorker.go
59 lines (54 loc) · 1020 Bytes
/
simpleWorker.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
package main
import (
"context"
"errors"
"github.com/dalmarcogd/gwp"
"github.com/dalmarcogd/gwp/pkg/worker"
"log"
"time"
)
func main() {
if err := gwp.
New().
Stats().
HealthCheck().
DebugPprof().
HandleError(func(w *worker.Worker, err error) {
log.Printf("Worker [%s] error: %s", w.Name, err)
}).
Worker(
"w1",
func(ctx context.Context) error {
select {
case <-time.After(10 * time.Second):
return errors.New("test")
case <-ctx.Done():
return errors.New("timeout")
}
},
worker.WithRestartAlways(),
worker.WithTimeout(11*time.Second)).
Worker(
"w2",
func(ctx context.Context) error {
select {
case <-time.After(30 * time.Second):
case <-ctx.Done():
return ctx.Err()
}
return nil
}).
Worker(
"w3",
func(ctx context.Context) error {
select {
case <-time.After(1 * time.Minute):
case <-ctx.Done():
return errors.New("test")
}
return nil
}).
Run(); err != nil {
panic(err)
}
}