Documentation
¶
Overview ¶
Package events is the Instance's change feed, served as server-sent events at /_emu/v1/events (FR-CORE-045, FR-UI-006): resource changes, Operation progress and Request log entries.
A Hub numbers every event and keeps the most recent ones so that a client reconnecting with Last-Event-ID receives what it missed. When it cannot (the events are gone, or the ID is from another process), the client is told it has a gap and must refetch everything.
Index ¶
Constants ¶
const ( // Resource is a store key written or deleted (ResourceChange). Resource = "resource" // Operation is an Operation created, progressed or deleted (OperationChange). Operation = "operation" // Request is a Request log entry (reqlog.Entry). Request = "request" // Reset says all state was replaced (Reset or State snapshot restore). Reset = "reset" // Gap says events were missed and cannot be replayed. Only Subscribe // produces it. Gap = "gap" )
Event types.
Variables ¶
This section is empty.
Functions ¶
func StoreObserver ¶
StoreObserver returns a store.Observer publishing Resource and Operation events to h, and a Reset event when the store is replaced.
Types ¶
type Event ¶
type Event struct {
// ID is "<epoch>-<seq>": epoch identifies the Hub, so that IDs from an
// earlier process are recognised as a gap.
ID string
Type string
Data json.RawMessage
}
Event is one numbered event.
type Hub ¶
type Hub struct {
// contains filtered or unexported fields
}
Hub fans events out to subscribers and retains the latest ones.
func (*Hub) Close ¶
func (h *Hub) Close()
Close ends every subscription; later events are discarded.
func (*Hub) Publish ¶
Publish sends an event of type typ with data marshalled as JSON. A nil Hub discards it.
func (*Hub) ServeHTTP ¶
func (h *Hub) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP streams events as text/event-stream. A client resuming with the Last-Event-ID header (or lastEventId query parameter) first receives what it missed, or a Gap event.
type OperationChange ¶
type OperationChange struct {
Service string `json:"service"`
Namespace string `json:"namespace"`
// Name is the Operation's store key, or its name for
// google.longrunning Operations.
Name string `json:"name"`
Done bool `json:"done"`
Deleted bool `json:"deleted,omitempty"`
}
OperationChange is the data of an Operation event.
type ResourceChange ¶
type ResourceChange struct {
// Service is the namespace's first segment: a Service ID, or "core"
// for state the emulator owns (Projects).
Service string `json:"service"`
Namespace string `json:"namespace"`
Key string `json:"key"`
Deleted bool `json:"deleted,omitempty"`
}
ResourceChange is the data of a Resource event.