notifications

package
Version: v0.11.20 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2021 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Consumer

type Consumer struct {
	Handlers map[types.ObjectType]ResourceNotificationHandler
}

Consumer allows consuming notifications by picking the correct handler to process it

func (*Consumer) Consume

func (c *Consumer) Consume(ctx context.Context, n *types.Notification)

Consume consumes a notification and passes it to the correct handler for further processing

type Message

type Message struct {
	// Notification is the notification that needs to be applied on the platform
	Notification *types.Notification

	// Resync indicates that full resync is needed
	// In this case Notification is nil
	// Resync messages are written in the channel:
	// - The first message in the channel, so we always start with a resync
	// - When notifications are lost (indicated by status 410 returned by SM)
	// - On regular interval based on configuration
	Resync bool
}

Message is the payload sent by the producer

type Producer

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

Producer reads notifications coming from the websocket connection and regularly triggers full resync

func NewProducer

func NewProducer(producerSettings *ProducerSettings, smSettings *sm.Settings) (*Producer, error)

NewProducer returns a configured producer for the given settings

func (*Producer) Start

func (p *Producer) Start(ctx context.Context, group *sync.WaitGroup) <-chan *Message

Start starts the producer in a new go-routine

type ProducerSettings

type ProducerSettings struct {
	// MinPingPeriod is the minimum allowed ping period
	MinPingPeriod time.Duration `mapstructure:"min_ping_period"`
	// Reconnect delay is the time between reconnects
	ReconnectDelay time.Duration `mapstructure:"reconnect_delay"`
	// PongTimeout is the maximum time to wait between a ping and a pong
	PongTimeout time.Duration `mapstructure:"pong_timeout"`
	// PingPeriodPercentage is the percentage of actual ping period compared to the max_ping_period returned by SM
	PingPeriodPercentage int64 `mapstructure:"ping_period_percentage"`
	// MessagesQueueSize is the size of the messages queue
	MessagesQueueSize int `mapstructure:"messages_queue_size"`
	// ResyncPeriod is the time between two resyncs
	ResyncPeriod time.Duration `mapstructure:"resync_period"`
}

ProducerSettings are the settings for the producer

func DefaultProducerSettings

func DefaultProducerSettings() *ProducerSettings

DefaultProducerSettings are the default settings for the producer

func (ProducerSettings) Validate

func (p ProducerSettings) Validate() error

Validate validates the producer settings

type ResourceNotificationHandler

type ResourceNotificationHandler interface {
	// OnCreate is called when a notification for creating a resource arrives
	OnCreate(ctx context.Context, notification *types.Notification)

	// OnUpdate is called when a notification for modifying a resource arrives
	OnUpdate(ctx context.Context, notification *types.Notification)

	// OnDelete is called when a notification for deleting a resource arrives
	OnDelete(ctx context.Context, notification *types.Notification)
}

ResourceNotificationHandler can handle notifications by processing the Payload

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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