pubsub

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2023 License: MPL-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package pubsub provides cluster-wide publishing and subscribing of events

Index

Constants

This section is empty.

Variables

View Source
var ErrSubscriptionTerminated = errors.New("broker terminated the subscription")

ErrSubscriptionTerminated is for use by subscribers to indicate that their subscription has been terminated by the broker.

Functions

func WriteSSEEvent

func WriteSSEEvent(w io.Writer, data []byte, event EventType, base64encode bool)

WriteSSEEvent writes an server-side-event to w. The data is optionally base64 encoded before being written.

Types

type Broker

type Broker[T any] struct {
	logr.Logger
	// contains filtered or unexported fields
}

Broker allows clients to subscribe to OTF events.

func NewBroker

func NewBroker[T any](logger logr.Logger, listener databaseListener, table string, getter GetterFunc[T]) *Broker[T]

func (*Broker[T]) Subscribe

func (b *Broker[T]) Subscribe(ctx context.Context) (<-chan Event[T], func())

Subscribe subscribes the caller to a stream of events. The caller can close the subscription by either canceling the context or calling the returned unsubscribe function.

type Event

type Event[T any] struct {
	Type    EventType
	Payload T
}

Event represents an event in the lifecycle of an otf resource

func NewCreatedEvent

func NewCreatedEvent[T any](payload T) Event[T]

func NewDeletedEvent

func NewDeletedEvent[T any](payload T) Event[T]

func NewUpdatedEvent

func NewUpdatedEvent[T any](payload T) Event[T]

type EventType

type EventType string

EventType identifies the type of event

const (
	EventError       EventType = "error"
	EventInfo        EventType = "info"
	EventLogChunk    EventType = "log_update"
	EventLogFinished EventType = "log_finished"
	EventVCS         EventType = "vcs_event"

	CreatedEvent EventType = "created"
	UpdatedEvent EventType = "updated"
	DeletedEvent EventType = "deleted"
)

type GetterFunc added in v0.0.53

type GetterFunc[T any] func(ctx context.Context, id string, action sql.Action) (T, error)

GetterFunc retrieves the type T using its unique id.

type SubscriptionService added in v0.2.0

type SubscriptionService[T any] interface {
	Subscribe(context.Context) (<-chan Event[T], func())
}

SubscriptionService is a service that provides subscriptions to events

Jump to

Keyboard shortcuts

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