Documentation ¶
Overview ¶
Package events contains the internal message bus used to broadcast events between goroutines representing jobs, watches, etc.
Index ¶
- Variables
- func NewEventTimeout(ctx context.Context, rx chan Event, tick time.Duration, name string)
- func NewEventTimer(ctx context.Context, rx chan Event, tick time.Duration, name string)
- type Event
- type EventBus
- func (bus *EventBus) DebugEvents() []Event
- func (bus *EventBus) Publish(event Event)
- func (bus *EventBus) PublishSignal(sig string)
- func (bus *EventBus) Register(publisher EventPublisher)
- func (bus *EventBus) SetReloadFlag()
- func (bus *EventBus) Shutdown()
- func (bus *EventBus) Subscribe(subscriber EventSubscriber)
- func (bus *EventBus) Unregister(publisher EventPublisher)
- func (bus *EventBus) Unsubscribe(subscriber EventSubscriber)
- func (bus *EventBus) Wait() bool
- type EventCode
- type EventPublisher
- type EventSubscriber
- type Publisher
- type Subscriber
Constants ¶
This section is empty.
Variables ¶
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 ¶
NewEventTimeout starts a goroutine on a timer that will send a TimerExpired event when the timer expires
Types ¶
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) PublishSignal ¶
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
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 ¶
FromString parses a string as an EventCode enum
type EventPublisher ¶
EventPublisher is an interface for publishers that register/unregister from the EventBus and publish Events.
type EventSubscriber ¶
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) Unregister ¶
func (pub *Publisher) Unregister()
Unregister unregisters the Publisher from the EventBus.
type Subscriber ¶
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.