-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprovider.go
56 lines (46 loc) · 1.62 KB
/
provider.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
// Package provider defines the basic provider subsystems for
// observing our networks of interest
package provider
import (
"context"
"time"
"github.com/rs/zerolog"
"github.com/0xPolygon/panoptichain/log"
"github.com/0xPolygon/panoptichain/network"
"github.com/0xPolygon/panoptichain/observer"
)
// Provider must be implemented by any system that's monitoring the
// state of a network.
type Provider interface {
// Refresh state is responsible for updating the provider state. All state
// updates should happen in this method of the provider. There should not be
// event publishing done is this method. The Start function in runner.go will
// call RefreshState of every provider before PublishEvents.
RefreshState(context.Context) error
// PublishEvents should given the current state of the provider, publish those
// messages to the corresponding event bus. PublishEvents should not modify
// state at all. The Start function in runner.go will call PublishEvents of
// every provider after RefreshState.
PublishEvents(context.Context) error
// SetEventBus is used to configure the providers currently used message bus.
SetEventBus(*observer.EventBus)
// PollingInterval returns how often the provider should refresh it state and
// publish events in seconds.
PollingInterval() uint
}
func timer(duration *time.Duration) func() {
start := time.Now()
return func() {
*duration = time.Since(start)
}
}
func NewLogger(n network.Network, provider string) zerolog.Logger {
network := ""
if n != nil {
network = n.GetName()
}
return log.With().
Str("network", network).
Str("provider", provider).
Logger()
}