events

package
v0.0.0-...-9398901 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2024 License: Apache-2.0 Imports: 2 Imported by: 1

README

Event Handling

package-feeds supports publishing specific application 'events' to be processed.

Configuration

events:
  sink: "stdout"
  filter:
    enabled_event_types: ["LOSSY_FEED"]
    disabled_event_types: []
    enabled_components: ["Feeds"]

Events

N.B Currently only events for potential loss during package polling are available.

Types:

  • "LOSSY_FEED" - Potential loss was detected in a feed

Components:

  • "Feeds" - Events which occur within feed logic

Sinks:

  • "stdout" - Logs events to stdout

Documentation

Index

Constants

View Source
const (
	// Event Types.
	LossyFeedEventType = "LOSSY_FEED"

	// Components.
	FeedsComponentType = "Feeds"
)
View Source
const (
	LoggingEventSinkType = "stdout"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event interface {
	GetComponent() string
	GetType() string
	GetMessage() string
}

type Filter

type Filter struct {
	EnabledEventTypes  []string `yaml:"enabled_event_types"`
	DisabledEventTypes []string `yaml:"disabled_event_types"`

	EnabledComponents []string `yaml:"enabled_components"`
}

func NewFilter

func NewFilter(enabledEventTypes, disabledEventTypes, enabledComponents []string) *Filter

Creates a filter for use with an event handler, nil can be provided for non values.

func (Filter) ShouldDispatch

func (f Filter) ShouldDispatch(e Event) bool

ShouldDispatch checks whether an event should be dispatched under the configured filter options. Options are applied as follows:

  • disabled event types are always disabled.
  • enabled event types are enabled
  • enabled components are enabled except for disabled event types.

type Handler

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

func NewHandler

func NewHandler(sink Sink, filter Filter) *Handler

func NewNullHandler

func NewNullHandler() *Handler

func (*Handler) DispatchEvent

func (h *Handler) DispatchEvent(e Event) error

Dispatches an event to the configured sink if it passes the configured filter.

func (*Handler) GetFilter

func (h *Handler) GetFilter() Filter

func (*Handler) GetSink

func (h *Handler) GetSink() Sink

type LoggingEventSink

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

func NewLoggingEventSink

func NewLoggingEventSink(logger *logrus.Logger) *LoggingEventSink

Creates an event sink which logs events using a provided logrus logger, fields "component" and "event_type" are applied to the logger and warnings are logged for each event.

func (LoggingEventSink) AddEvent

func (sink LoggingEventSink) AddEvent(e Event) error

type LossyFeedEvent

type LossyFeedEvent struct {
	Feed string
}

func (LossyFeedEvent) GetComponent

func (e LossyFeedEvent) GetComponent() string

func (LossyFeedEvent) GetMessage

func (e LossyFeedEvent) GetMessage() string

func (LossyFeedEvent) GetType

func (e LossyFeedEvent) GetType() string

type MockEvent

type MockEvent struct {
	Component string
	Type      string
	Message   string
}

func (MockEvent) GetComponent

func (e MockEvent) GetComponent() string

func (MockEvent) GetMessage

func (e MockEvent) GetMessage() string

func (MockEvent) GetType

func (e MockEvent) GetType() string

type MockSink

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

func (*MockSink) AddEvent

func (s *MockSink) AddEvent(e Event) error

func (*MockSink) GetEvents

func (s *MockSink) GetEvents() []Event

type Sink

type Sink interface {
	AddEvent(e Event) error
}

Jump to

Keyboard shortcuts

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