Sha256: 614f83695fc0939526fa16795000c9cffae86dfac2cb51e702409cc21f23f379

Contents?: true

Size: 986 Bytes

Versions: 14

Compression:

Stored size: 986 Bytes

Contents

require 'peek/adapters/base'
require 'elasticsearch'

module Peek
  module Adapters
    class Elasticsearch < Base
      def initialize(options = {})
        @client = options.fetch(:client, ::Elasticsearch::Client.new)
        @expires_in = Integer(options.fetch(:expires_in, 60 * 30) * 1000)
        @index = options.fetch(:index, 'peek_requests_index')
        @type = options.fetch(:type, 'peek_request')
      end

      def get(request_id)
        result = @client.get_source index: @index, type: @type, id: "#{request_id}"
        result.to_json
      rescue ::Elasticsearch::Transport::Transport::Errors::NotFound
        # pass
      end

      def save
        @client.index index: @index,
                      type: @type,
                      id: "#{Peek.request_id}",
                      body: Peek.results.to_json,
                      ttl: @expires_in
      rescue ::Elasticsearch::Transport::Transport::Errors::BadRequest
        false
      end

    end
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/peek-1.0.1/lib/peek/adapters/elasticsearch.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/peek-1.0.1/lib/peek/adapters/elasticsearch.rb
zuora_connect_ui-0.9.1 vendor/ruby/2.6.0/gems/peek-1.0.1/lib/peek/adapters/elasticsearch.rb
zuora_connect_ui-0.9.0 vendor/ruby/2.6.0/gems/peek-1.0.1/lib/peek/adapters/elasticsearch.rb
zuora_connect_ui-0.8.3 vendor/ruby/2.6.0/gems/peek-1.0.1/lib/peek/adapters/elasticsearch.rb
zuora_connect_ui-0.8.2 vendor/ruby/2.6.0/gems/peek-1.0.1/lib/peek/adapters/elasticsearch.rb
zuora_connect_ui-0.8.1 vendor/ruby/2.6.0/gems/peek-1.0.1/lib/peek/adapters/elasticsearch.rb
zuora_connect_ui-0.8.0 vendor/ruby/2.6.0/gems/peek-1.0.1/lib/peek/adapters/elasticsearch.rb
zuora_connect_ui-0.7.1 vendor/ruby/2.6.0/gems/peek-1.0.1/lib/peek/adapters/elasticsearch.rb
zuora_connect_ui-0.7.0 vendor/ruby/2.6.0/gems/peek-1.0.1/lib/peek/adapters/elasticsearch.rb
peek-1.0.1 lib/peek/adapters/elasticsearch.rb
peek-0.2.0 lib/peek/adapters/elasticsearch.rb
peek-0.1.10 lib/peek/adapters/elasticsearch.rb
peek-0.1.9 lib/peek/adapters/elasticsearch.rb