-
Notifications
You must be signed in to change notification settings - Fork 45
/
blockmessage.go
43 lines (33 loc) · 1.12 KB
/
blockmessage.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
package messages
import (
"context"
"go.opencensus.io/tag"
"go.opentelemetry.io/otel/api/global"
"go.opentelemetry.io/otel/api/trace"
"go.opentelemetry.io/otel/label"
"github.com/filecoin-project/sentinel-visor/metrics"
"github.com/filecoin-project/sentinel-visor/model"
)
type BlockMessage struct {
Height int64 `pg:",pk,notnull,use_zero"`
Block string `pg:",pk,notnull"`
Message string `pg:",pk,notnull"`
}
func (bm *BlockMessage) Persist(ctx context.Context, s model.StorageBatch) error {
ctx, _ = tag.New(ctx, tag.Upsert(metrics.Table, "block_messages"))
stop := metrics.Timer(ctx, metrics.PersistDuration)
defer stop()
return s.PersistModel(ctx, bm)
}
type BlockMessages []*BlockMessage
func (bms BlockMessages) Persist(ctx context.Context, s model.StorageBatch) error {
if len(bms) == 0 {
return nil
}
ctx, span := global.Tracer("").Start(ctx, "BlockMessages.Persist", trace.WithAttributes(label.Int("count", len(bms))))
defer span.End()
ctx, _ = tag.New(ctx, tag.Upsert(metrics.Table, "block_messages"))
stop := metrics.Timer(ctx, metrics.PersistDuration)
defer stop()
return s.PersistModel(ctx, bms)
}