title | expires_at | tags | ||
---|---|---|---|---|
BBS Events |
never |
|
The BBS emits events when a DesiredLRP, ActualLRP or Task 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.
Deprecated in favor of subscribing to LRP Instance Events
You can use the SubscribeToEvents(logger lager.Logger) (events.EventSource, error)
client method to subscribe to lrp events. For example:
client := bbs.NewClient(url)
eventSource, err := client.SubscribeToEvents(logger)
if err != nil {
log.Printf("failed to subscribe to lrp events: " + err.Error())
}
Alternatively you can use the SubscribeToEventsByCellID
client method to subscribe to events that are relevant to the given cell. For example:
client := bbs.NewClient(url)
eventSource, err := client.SubscribeToEventsByCellID(logger, "some-cell-id")
if err != nil {
log.Printf("failed to subscribe to lrp events: " + err.Error())
}
Events relevant to the cell are defined as:
ActualLRPCreatedEvent
that is running on that cellActualLRPRemovedEvent
that used to run on that cellActualLRPChangedEvent
that used to/started running on that cellActualLRPCrashedEvent
that used to run on that cell
Note Passing an empty string cellID
argument to SubscribeToEventsByCellID
is equivalent to calling SubscribeToEvents
Note SubscribeToEventsByCellID
and SubscribeToEvents
do not have events related to Tasks.
You can use the SubscribeToInstanceEvents(logger lager.Logger) (events.EventSource, error)
client method to subscribe to lrp instance events. For example:
client := bbs.NewClient(url)
eventSource, err := client.SubscribeToInstanceEvents(logger)
if err != nil {
log.Printf("failed to subscribe to lrp instance events: " + err.Error())
}
Alternatively you can use the SubscribeToInstanceEventsByCellID
client method to subscribe to events that are relevant to the given cell. For example:
client := bbs.NewClient(url)
eventSource, err := client.SubscribeToInstanceEventsByCellID(logger, "some-cell-id")
if err != nil {
log.Printf("failed to subscribe to instance lrp events: " + err.Error())
}
Events relevant to the cell are defined as:
ActualLRPInstanceCreatedEvent
that is running on that cellActualLRPInstanceRemovedEvent
that used to run on that cellActualLRPInstanceChangedEvent
that used to/started running on that cellActualLRPCrashedEvent
that used to run on that cell
Note Passing an empty string cellID
argument to SubscribeToInstanceEventsByCellID
is equivalent to calling SubscribeToInstanceEvents
Note SubscribeToInstanceEventsByCellID
and SubscribeToInstanceEvents
do not have events related to Tasks.
You can use the SubscribeToTaskEvents(logger lager.Logger) (events.EventSource, error)
client method to subscribe to task events. For example:
client := bbs.NewClient(url)
eventSource, err := client.SubscribeToTaskEvents(logger)
if err != nil {
log.Printf("failed to subscribe to task events: " + err.Error())
}
Once an EventSource
is created, you can then loop through the events by calling
Next in a
loop, for example:
event, err := eventSource.Next()
if err != nil {
switch err {
case events.ErrUnrecognizedEventType:
//log and skip unrecognized events
logger.Error("failed-getting-next-event", err)
case events.ErrSourceClosed:
//log and try to re-subscribe
logger.Error("failed-getting-next-event", err)
resubscribeChan <- err
return
default:
//log and handle a nil event for any other error
logger.Error("failed-getting-next-event", err)
time.Sleep(retryPauseInterval)
eventChan <- nil
}
}
log.Printf("received event: %#v", event)
In the case there is an ErrUnrecognizedEventType
error, the client should skip
it and move to the next event. If the error is an ErrSourceClosed
, the client
should try to resubscribe to the event source. The example above uses a channel
to handle the re-subscription.
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.
Deprecated in favor of ActualLRPInstanceCreatedEvent
When a new ActualLRP is created, a
ActualLRPCreatedEvent
is emitted. The value of the ActualLrpGroup
field contains more information
about the ActualLRP.
Deprecated in favor of ActualLRPInstanceChangedEvent
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.
Deprecated in favor of ActualLRPInstanceRemovedEvent
When a ActualLRP is removed, a
ActualLRPRemovedEvent
is emitted. The value of the ActualLrpGroup
field contains information about the
ActualLRP that was just removed.
When a new ActualLRP instance is created, a
ActualLRPInstanceCreatedEvent
is emitted. The value of the ActualLrp
field contains more information
about the ActualLRP.
When a ActualLRP changes, a
ActualLRPInstanceChangedEvent
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
ActualLRPInstanceRemovedEvent
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.
When a new Task is created, a
TaskCreatedEvent
is emitted. The value of the Task
field contains information about the
Task that was just created.
When a Task changes, a
TaskChangedEvent
is emitted. The value of the Before
and After
fields have information about the
Task before and after the change.
When a Task is deleted, a
TaskRemovedEvent
is emitted. The field value of Task
will have information about the
Task that was just removed.