require "sidekiq"
require "search_config"

module Elasticsearch
  class BulkIndexWorker
    include Sidekiq::Worker

    def logger
      Logging.logger[self]
    end

    sidekiq_options :queue => :bulk

    def perform(index_name, document_hashes)
      noun = document_hashes.size > 1 ? "documents" : "document"
      logger.info "Indexing #{document_hashes.size} queued #{noun} into #{index_name}"

      index(index_name).bulk_index(document_hashes)
    end

  private
    def index(index_name)
      SearchConfig.new.search_server.index(index_name)
    end
  end
end

require "sidekiq"
require "search_config"

module Elasticsearch
  class BulkIndexWorker
    include Sidekiq::Worker
    sidekiq_options :retry => 5

    def logger
      Logging.logger[self]
    end

    sidekiq_options :queue => :bulk

    def perform(index_name, document_hashes)
      noun = document_hashes.size > 1 ? "documents" : "document"
      logger.info "Indexing #{document_hashes.size} queued #{noun} into #{index_name}"

      index(index_name).bulk_index(document_hashes)
    end

  private
    def index(index_name)
      SearchConfig.new.search_server.index(index_name)
    end
  end
end

Make the indexing worker retry fewer times.
Make the indexing worker retry fewer times.

The default number of retries is 25, with exponential backoff, which
will cause a request to be retried for about three weeks after it's
initially submitted. By this time, there's a good chance the document
will be out of date anyway. Five retries over about 7 minutes seems like
a far more sensible default.

See <https://github.com/mperham/sidekiq/wiki/Error-Handling>.
