forked from gateway-fm/service-pool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.go
49 lines (41 loc) · 924 Bytes
/
example.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
package pool
import (
"time"
"github.com/gateway-fm/prover-pool-lib/prover"
)
func Example() {
pool := NewServicesPool(&ServicesPoolsOpts{
Name: "example",
ListOpts: &ServicesListOpts{
TryUpTries: 5,
TryUpInterval: 5 * time.Second,
ChecksInterval: 5 * time.Second,
},
})
pool.Start(true)
// when prover calls prover-pool-service
prv, err := prover.NewProver(&prover.ProverOpts{
Name: "exampleProver1",
Addr: "127.0.0.1:8080",
Healthcheck: ProverMockHealthcheck(10 * time.Second),
Tags: map[string]struct{}{
"forkId1": struct{}{},
"public": struct{}{},
},
})
if err != nil {
panic(err)
}
pool.AddService(prv)
// when we need to call prover we do:
srv := pool.NextLeastLoaded("forkId1")
leastLoadedPrv, ok := srv.(prover.IProver)
if !ok {
panic("oh shit")
}
resp, err := leastLoadedPrv.DoRequest(nil)
if err != nil {
panic(err)
}
_ = resp
}