/
keeper.go
63 lines (54 loc) · 1.15 KB
/
keeper.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
package keeper
import (
"context"
"time"
"github.com/fox-one/pando/core"
"github.com/fox-one/pando/worker/keeper/wallet"
"github.com/fox-one/pkg/logger"
"golang.org/x/sync/errgroup"
)
func New(
cats core.CollateralStore,
oracles core.OracleStore,
vaults core.VaultStore,
flips core.FlipStore,
walletz core.WalletService,
notifier core.Notifier,
system *core.System,
) *Keeper {
return &Keeper{
cats: cats,
oracles: oracles,
vaults: vaults,
flips: flips,
walletz: wallet.FilterTrace(walletz, time.Minute),
notifier: notifier,
system: system,
}
}
type Keeper struct {
cats core.CollateralStore
oracles core.OracleStore
vaults core.VaultStore
flips core.FlipStore
walletz core.WalletService
notifier core.Notifier
system *core.System
}
func (w *Keeper) Run(ctx context.Context) error {
log := logger.FromContext(ctx).WithField("worker", "keeper")
ctx = logger.WithContext(ctx, log)
g := errgroup.Group{}
jobs := []func(ctx2 context.Context) error{
w.foldCats,
w.dealFlips,
w.scanVaults,
}
for idx := range jobs {
f := jobs[idx]
g.Go(func() error {
return f(ctx)
})
}
return g.Wait()
}