forked from ava-labs/ortelius
-
Notifications
You must be signed in to change notification settings - Fork 0
/
services.go
69 lines (59 loc) · 1.6 KB
/
services.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
64
65
66
67
68
69
package services
import (
"context"
"time"
cblock "github.com/corpetty/ortelius/models"
kafkaMessage "github.com/segmentio/kafka-go"
"github.com/gocraft/dbr/v2"
"github.com/gocraft/health"
)
type Consumable interface {
ID() string
ChainID() string
Body() []byte
Timestamp() int64
Nanosecond() int64
KafkaMessage() *kafkaMessage.Message
}
// Consumer takes in Consumables and adds them to the service's backend
type Consumer interface {
Name() string
Bootstrap(context.Context, *Connections, Persist) error
Consume(context.Context, *Connections, Consumable, Persist) error
ConsumeConsensus(context.Context, *Connections, Consumable, Persist) error
ParseJSON([]byte) ([]byte, error)
}
type ConsumerCChain interface {
Name() string
Consume(context.Context, *Connections, Consumable, *cblock.Block, Persist) error
ParseJSON([]byte) ([]byte, error)
}
// ConsumerCtx
type ConsumerCtx struct {
ctx context.Context
job *health.Job
db dbr.SessionRunner
time time.Time
persist Persist
}
func NewConsumerContext(
ctx context.Context,
job *health.Job,
db dbr.SessionRunner,
ts int64,
nanosecond int64,
persist Persist,
) ConsumerCtx {
return ConsumerCtx{
ctx: ctx,
job: job,
db: db,
time: time.Unix(ts, nanosecond),
persist: persist,
}
}
func (ic *ConsumerCtx) Time() time.Time { return ic.time }
func (ic *ConsumerCtx) Job() *health.Job { return ic.job }
func (ic *ConsumerCtx) DB() dbr.SessionRunner { return ic.db }
func (ic *ConsumerCtx) Ctx() context.Context { return ic.ctx }
func (ic *ConsumerCtx) Persist() Persist { return ic.persist }