Sha256: 91ac9ed4b5abd7bfa8ea3621ebbc9d88b5676461efb123a7481fcd242a28e254

Contents?: true

Size: 843 Bytes

Versions: 8

Compression:

Stored size: 843 Bytes

Contents

module SearchKit
  class Polling
    # The logic of interacting with the event service to retrieve and process
    # events is contained here.
    #
    class Process
      def self.perform(channel, &block)
        new(channel, &block).perform
      end

      attr_reader :block, :channel, :client

      def initialize(channel, &block)
        @block   = block
        @channel = channel
        @client  = SearchKit::Clients::Events.new
      end

      def perform
        events.each do |event|
          begin
            block.call(event)
          rescue
            raise
          else
            client.complete(event.id)
          end
        end
      end

      private

      def events
        response = client.pending(channel)
        response.fetch(:data, []).map { |raw| OpenStruct.new(raw) }
      end
    end

  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
search-kit-0.0.10 lib/search_kit/polling/process.rb
search-kit-0.0.9 lib/search_kit/polling/process.rb
search-kit-0.0.8 lib/search_kit/polling/process.rb
search-kit-0.0.7 lib/search_kit/polling/process.rb
search-kit-0.0.6 lib/search_kit/polling/process.rb
search-kit-0.0.5 lib/search_kit/polling/process.rb
search-kit-0.0.4 lib/search_kit/polling/process.rb
search-kit-0.0.3 lib/search_kit/polling/process.rb