The BBS emits events when a DesiredLRP or ActualLRP is created, updated, or deleted. The following sections provide details on how to subscribe to those events as well as the type of events supported by the BBS.
You can use the SubscribeToEvents(logger lager.Logger) (events.EventSource, error)
client method to subscribe to events. For example:
client := bbs.NewClient(url)
eventSource, err := client.SubscribeToEvents(logger)
if err != nil {
log.Printf("failed to subscribe to events: " + err.Error())
}
You can then loop through the events by calling Next in a loop, for example:
event, err := eventSource.Next()
if err != nil {
log.Printf("failed to get next event: " + err.Error())
}
log.Printf("received event: %#v", event)
To access the event field values, you must convert the event to the right
type. You can use the EventType
method to determine the type of the event,
for example:
if event.EventType() == models.EventTypeActualLRPCrashed {
crashEvent := event.(*models.ActualLRPCrashedEvent)
log.Printf("lrp has crashed. err: %s", crashEvent.CrashReason)
}
The following types of events are emitted:
When a new DesiredLRP is created, a
DesiredLRPCreatedEvent
is emitted. The value of the DesiredLrp
field contains information about the
DesiredLRP that was just created.
When a DesiredLRP changes, a
DesiredLRPChangedEvent
is emitted. The value of the Before
and After
fields have information about the
DesiredLRP before and after the change.
When a DesiredLRP is deleted, a
DesiredLRPRemovedEvent
is emitted. The field value of DesiredLrp
will have information about the
DesiredLRP that was just removed.
When a new ActualLRP is created, a
ActualLRPCreatedEvent
is emitted. The value of the ActualLrpGroup
field contains more information
about the ActualLRP.
When a ActualLRP changes, a
ActualLRPChangedEvent
is emitted. The value of the Before
and After
fields contains information about the
ActualLRP state before and after the change.
When a ActualLRP is removed, a
ActualLRPRemovedEvent
is emitted. The value of the ActualLrp
field contains information about the
ActualLRP that was just removed.
When a ActualLRP crashes a ActualLRPCrashedEvent is emitted. The event will have the following field values:
ActualLRPKey
: The LRP key of the ActualLRP.ActualLRPInstanceKey
: The instance key of the ActualLRP.CrashCount
: The number of times the ActualLRP has crashed, including this latest crash.CrashReason
: The last error that caused the ActualLRP to crash.Since
: The timestamp when the ActualLRP last crashed, in nanoseconds in the Unix epoch.