mirror of
https://github.com/luxfi/indexer.git
synced 2026-09-24 00:25:37 +00:00
Co-authored-by: dhrubabasu <[email protected]> Co-authored-by: Patrick O'Grady <[email protected]> Co-authored-by: Stephen <[email protected]>
52 lines
1.2 KiB
Go
52 lines
1.2 KiB
Go
// (c) 2021, Ava Labs, Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package stream
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"time"
|
|
|
|
"github.com/ava-labs/ortelius/cfg"
|
|
"github.com/ava-labs/ortelius/db"
|
|
"github.com/ava-labs/ortelius/servicesctrl"
|
|
"github.com/ava-labs/ortelius/utils"
|
|
)
|
|
|
|
var (
|
|
processorFailureRetryInterval = 200 * time.Millisecond
|
|
|
|
// ErrNoMessage is no message
|
|
ErrNoMessage = errors.New("no message")
|
|
)
|
|
|
|
type ProcessorFactoryChainDB func(*servicesctrl.Control, cfg.Config, string, string) (ProcessorDB, error)
|
|
type ProcessorFactoryInstDB func(*servicesctrl.Control, cfg.Config) (ProcessorDB, error)
|
|
|
|
type ProcessorDB interface {
|
|
Process(*utils.Connections, *db.TxPool) error
|
|
Close() error
|
|
ID() string
|
|
Topic() []string
|
|
}
|
|
|
|
func UpdateTxPool(
|
|
ctxTimeout time.Duration,
|
|
conns *utils.Connections,
|
|
persist db.Persist,
|
|
txPool *db.TxPool,
|
|
sc *servicesctrl.Control,
|
|
) error {
|
|
sess := conns.DB().NewSessionForEventReceiver(conns.Stream().NewJob("update-tx-pool"))
|
|
|
|
ctx, cancelCtx := context.WithTimeout(context.Background(), ctxTimeout)
|
|
defer cancelCtx()
|
|
|
|
err := persist.InsertTxPool(ctx, sess, txPool)
|
|
if err == nil {
|
|
sc.Enqueue(txPool)
|
|
}
|
|
return err
|
|
}
|