class RedfishClient::EventListener

EventListener class can be used to stream events from Redfish service. It is a thin wrapper around SSE listener that does the dirty work of splitting each event into its EventRecords and reporting them as separate events.

Public Class Methods

new(sse_client) click to toggle source

Create new EventListener instance.

@param sse_client [ServerSentEvents::Client] SSE client

# File lib/redfish_client/event_listener.rb, line 15
def initialize(sse_client)
  @sse_client = sse_client
end

Public Instance Methods

listen() { |r| ... } click to toggle source

Stream events from redfish service.

Events that this method yields are actually EventRecords, extracted from the actual Redfish Event.

# File lib/redfish_client/event_listener.rb, line 23
def listen
  @sse_client.listen do |event|
    split_event_into_records(event).each { |r| yield(r) }
  end
end

Private Instance Methods

split_event_into_records(event) click to toggle source
# File lib/redfish_client/event_listener.rb, line 31
def split_event_into_records(event)
  JSON.parse(event.data).fetch("Events", [])
end