events

package
v0.0.0-...-8018142 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2021 License: MPL-2.0 Imports: 6 Imported by: 12

README

events

GoDoc

Documentation

Overview

Package events contains the internal message bus used to broadcast events between goroutines representing jobs, watches, etc.

Index

Constants

This section is empty.

Variables

View Source
var (
	GlobalStartup          = Event{Code: Startup, Source: "global"}
	GlobalShutdown         = Event{Code: Shutdown, Source: "global"}
	NonEvent               = Event{Code: None, Source: ""}
	GlobalEnterMaintenance = Event{Code: EnterMaintenance, Source: "global"}
	GlobalExitMaintenance  = Event{Code: ExitMaintenance, Source: "global"}
	QuitByTest             = Event{Code: Quit, Source: "closed"}
)

global events

Functions

func NewEventTimeout

func NewEventTimeout(
	ctx context.Context,
	rx chan Event,
	tick time.Duration,
	name string,
)

NewEventTimeout starts a goroutine on a timer that will send a TimerExpired event when the timer expires

func NewEventTimer

func NewEventTimer(
	ctx context.Context,
	rx chan Event,
	tick time.Duration,
	name string,
)

NewEventTimer starts a goroutine with a timer that will send a TimerExpired event every time the timer expires

Types

type Event

type Event struct {
	Code   EventCode
	Source string
}

Event represents a single message in the EventBus

type EventBus

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

EventBus manages the state of and transmits messages to all its Subscribers

func NewEventBus

func NewEventBus() *EventBus

NewEventBus initializes an EventBus. We need this rather than a struct literal so that we know our channels are non-nil (which block sends).

func (*EventBus) DebugEvents

func (bus *EventBus) DebugEvents() []Event

DebugEvents ...

func (*EventBus) Publish

func (bus *EventBus) Publish(event Event)

Publish an Event to all Subscribers

func (*EventBus) PublishSignal

func (bus *EventBus) PublishSignal(sig string)

PublishSignal publishes a signal event through the EventBus to any Jobs that are subscribed to trigger on them.

func (*EventBus) Register

func (bus *EventBus) Register(publisher EventPublisher)

Register the Publisher for all Events

func (*EventBus) SetReloadFlag

func (bus *EventBus) SetReloadFlag()

SetReloadFlag sets the flag that Wait will use to signal to the main App that we want to restart rather than be shut down

func (*EventBus) Shutdown

func (bus *EventBus) Shutdown()

Shutdown asks all Subscribers to halt by sending the GlobalShutdown message. Subscribers are responsible for handling this message.

func (*EventBus) Subscribe

func (bus *EventBus) Subscribe(subscriber EventSubscriber)

Subscribe the Subscriber for all Events

func (*EventBus) Unregister

func (bus *EventBus) Unregister(publisher EventPublisher)

Unregister the Publisher from all Events

func (*EventBus) Unsubscribe

func (bus *EventBus) Unsubscribe(subscriber EventSubscriber)

Unsubscribe the Subscriber from all Events

func (*EventBus) Wait

func (bus *EventBus) Wait() bool

Wait blocks until the EventBus registry is unpopulated. Returns true if the "reload" flag was set.

type EventCode

type EventCode int

EventCode is an enum for Events

const (
	None        EventCode = iota // placeholder nil-event
	ExitSuccess                  // emitted when a Runner's exec completes with 0 exit code
	ExitFailed                   // emitted when a Runner's exec completes with non-0 exit code
	Stopping                     // emitted when a Runner is about to stop
	Stopped                      // emitted when a Runner has stopped
	StatusHealthy
	StatusUnhealthy
	StatusChanged
	TimerExpired
	EnterMaintenance
	ExitMaintenance
	Error
	Quit
	Metric
	Startup  // fired once after events are set up and event loop is started
	Shutdown // fired once after all jobs exit or on receiving SIGTERM
	Signal   // fired when a UNIX signal hits a CP process/supervisor
)

EventCode enum

func FromString

func FromString(codeName string) (EventCode, error)

FromString parses a string as an EventCode enum

func (EventCode) String

func (i EventCode) String() string

type EventPublisher

type EventPublisher interface {
	Publish(Event)
	Register(*EventBus)
	Unregister()
}

EventPublisher is an interface for publishers that register/unregister from the EventBus and publish Events.

type EventSubscriber

type EventSubscriber interface {
	Subscribe(*EventBus)
	Unsubscribe()
	Receive(Event)
}

EventSubscriber is an interface for subscribers that subscribe/unsubscribe from the EventBus and receive Events.

type Publisher

type Publisher struct {
	Bus *EventBus
}

Publisher represents an object with a Bus that implements the EventPublisher interface.

func (*Publisher) Publish

func (pub *Publisher) Publish(event Event)

Publish publishes an Event across the Publisher's EventBus

func (*Publisher) Register

func (pub *Publisher) Register(bus *EventBus)

Register registers the Publisher with the EventBus.

func (*Publisher) Unregister

func (pub *Publisher) Unregister()

Unregister unregisters the Publisher from the EventBus.

func (*Publisher) Wait

func (pub *Publisher) Wait()

Wait blocks for the EventBus wait group counter to count down to zero.

type Subscriber

type Subscriber struct {
	Rx  chan Event
	Bus *EventBus
}

Subscriber represents an object which recieves events through the Event bus through its receive channel.

func (*Subscriber) Receive

func (sub *Subscriber) Receive(event Event)

Receive receives an Event through the receive channel.

func (*Subscriber) Subscribe

func (sub *Subscriber) Subscribe(bus *EventBus)

Subscribe subscribes a subscriber to the EventBus

func (*Subscriber) Unsubscribe

func (sub *Subscriber) Unsubscribe()

Unsubscribe unsubscribes the subscriber from the EventBus.

func (*Subscriber) Wait

func (sub *Subscriber) Wait()

Wait waits for the subscriber's EventBus to complete its wait group.

Jump to

Keyboard shortcuts

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