class SearchKit::Polling::Process

The logic of interacting with the event service to retrieve and process events is contained here.

Attributes

block[R]
channel[R]
client[R]

Public Class Methods

new(channel, &block) click to toggle source
# File lib/search_kit/polling/process.rb, line 13
def initialize(channel, &block)
  @block   = block
  @channel = channel
  @client  = SearchKit::Clients::Events.new
end
perform(channel, &block) click to toggle source
# File lib/search_kit/polling/process.rb, line 7
def self.perform(channel, &block)
  new(channel, &block).perform
end

Public Instance Methods

perform() click to toggle source
# File lib/search_kit/polling/process.rb, line 19
def perform
  events.each do |event|
    begin
      block.call(event)
    rescue
      raise
    else
      client.complete(event.id)
    end
  end
end

Private Instance Methods

events() click to toggle source
# File lib/search_kit/polling/process.rb, line 33
def events
  response = client.pending(channel)
  response.fetch(:data, []).map { |raw| OpenStruct.new(raw) }
end