indexer

package
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 12, 2024 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Indexer

type Indexer[T Input] struct {
	Processor  Processor[T]
	Datasource datasources.Datasource[T]
	// contains filtered or unexported fields
}

Indexer generic indexer for fetching and processing data

func New

func New[T Input](processor Processor[T], datasource datasources.Datasource[T]) *Indexer[T]

New create new generic indexer

func (*Indexer[T]) Run

func (i *Indexer[T]) Run(ctx context.Context) (err error)

func (*Indexer[T]) Shutdown

func (i *Indexer[T]) Shutdown() error

func (*Indexer[T]) ShutdownWithContext

func (i *Indexer[T]) ShutdownWithContext(ctx context.Context) (err error)

func (*Indexer[T]) ShutdownWithTimeout

func (i *Indexer[T]) ShutdownWithTimeout(timeout time.Duration) error

type IndexerWorker

type IndexerWorker interface {
	Shutdown() error
	ShutdownWithTimeout(timeout time.Duration) error
	ShutdownWithContext(ctx context.Context) (err error)
	Run(ctx context.Context) (err error)
}

type Input

type Input interface {
	BlockHeader() types.BlockHeader
}

type Processor

type Processor[T Input] interface {
	Name() string

	// Process processes the input data and indexes it.
	Process(ctx context.Context, inputs []T) error

	// CurrentBlock returns the latest indexed block header.
	CurrentBlock(ctx context.Context) (types.BlockHeader, error)

	// GetIndexedBlock returns the indexed block header by the specified block height.
	GetIndexedBlock(ctx context.Context, height int64) (types.BlockHeader, error)

	// RevertData revert synced data to the specified block height for re-indexing.
	RevertData(ctx context.Context, from int64) error

	// VerifyStates verifies the states of the indexed data and the indexer
	// to ensure the last shutdown was graceful and no missing data.
	VerifyStates(ctx context.Context) error

	// Shutdown gracefully stops the processor. Database connections, network calls, leftover states, etc. should be closed and cleaned up here.
	Shutdown(ctx context.Context) error
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL