event

package
v1.13.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddMessageToBatch

func AddMessageToBatch(ctx context.Context, batch *Batch, msg kafka.Message, handler Handler, errChan chan error)

AddMessageToBatch will attempt to add the message to the batch and determine if it should be processed.

func ProcessBatch

func ProcessBatch(ctx context.Context, handler Handler, batch *Batch, errChan chan error)

ProcessBatch will attempt to handle and commit the batch, or shutdown if something goes horribly wrong.

Types

type Batch

type Batch struct {
	// contains filtered or unexported fields
}

Batch handles adding raw messages to a batch of ObservationExtracted events.

func NewBatch

func NewBatch(batchSize int) *Batch

NewBatch returns a new batch instance of the given size.

func (*Batch) Add

func (batch *Batch) Add(ctx context.Context, message Message)

Add a message to the batch.

func (*Batch) Clear

func (batch *Batch) Clear()

Clear will reset to batch to contain no events.

func (*Batch) Commit

func (batch *Batch) Commit()

Commit is called when the batch has been processed. The last message has been released already, so at this point we just need to commit

func (*Batch) Events

func (batch *Batch) Events() []*ObservationExtracted

Events returns the events currenty in the batch.

func (*Batch) IsEmpty

func (batch *Batch) IsEmpty() bool

IsEmpty returns true if the batch has no events in it.

func (*Batch) IsFull

func (batch *Batch) IsFull() bool

IsFull returns true if the batch is full based on the configured maxSize.

func (*Batch) Size

func (batch *Batch) Size() int

Size returns the number of events currently in the batch.

type BatchHandler

type BatchHandler struct {
	// contains filtered or unexported fields
}

BatchHandler handles batches of ObservationExtracted events that contain CSV row data.

func NewBatchHandler

func NewBatchHandler(
	observationMapper ObservationMapper,
	observationStore ObservationStore,
	resultWriter ResultWriter,
	errorReporter reporter.ErrorReporter) *BatchHandler

NewBatchHandler returns a new BatchHandler to use the given observation mapper / store.

func (BatchHandler) Handle

func (handler BatchHandler) Handle(ctx context.Context, events []*ObservationExtracted) error

Handle the given slice of ObservationExtracted events.

type Consumer

type Consumer struct {
	// contains filtered or unexported fields
}

Consumer consumes event messages.

func NewConsumer

func NewConsumer() *Consumer

NewConsumer returns a new consumer instance.

func (*Consumer) Close

func (consumer *Consumer) Close(ctx context.Context) (err error)

Close safely closes the consumer and releases all resources

func (*Consumer) Consume

func (consumer *Consumer) Consume(messageConsumer MessageConsumer,
	batchSize int,
	handler Handler,
	batchWaitTime time.Duration,
	errChan chan error)

Consume convert them to event instances, and pass the event to the provided handler.

type Handler

type Handler interface {
	Handle(ctx context.Context, events []*ObservationExtracted) error
}

Handler represents a handler for processing a batch of events.

type Message

type Message interface {
	GetData() []byte
	Mark()
	Commit()
}

Message represents a single message to be added to the batch.

type MessageConsumer

type MessageConsumer interface {
	Channels() *kafka.ConsumerGroupChannels
}

MessageConsumer provides a generic interface for consuming []byte messages (from Kafka)

type ObservationExtracted

type ObservationExtracted struct {
	RowIndex   int64  `avro:"row_index"`
	Row        string `avro:"row"`
	InstanceID string `avro:"instance_id"`
}

ObservationExtracted is the data that is output for each observation extracted.

func Unmarshal

func Unmarshal(message Message) (*ObservationExtracted, error)

Unmarshal converts an event instance to []byte.

type ObservationMapper

type ObservationMapper interface {
	Map(ctx context.Context, row string, rowIndex int64, instanceID string) (*models.Observation, error)
}

ObservationMapper handles the conversion from row data to observation instances.

type ObservationStore

type ObservationStore interface {
	SaveAll(ctx context.Context, observations []*models.Observation) ([]*observation.Result, error)
}

ObservationStore handles the persistence of observations.

type ResultWriter

type ResultWriter interface {
	Write(ctx context.Context, results []*observation.Result)
}

ResultWriter dependency that outputs results

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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