class SearchSolrTools::Errors::HarvestError

Constants

ERRCODE_DESC
ERRCODE_DOCUMENT_INVALID
ERRCODE_INGEST_ERROR
ERRCODE_OTHER
ERRCODE_SOLR_PING
ERRCODE_SOURCE_HARVEST_ERROR
ERRCODE_SOURCE_NO_RESULTS
ERRCODE_SOURCE_PING
PING_ERRCODE_MAP
STATUS_ERRCODE_MAP

Public Class Methods

code_to_list(code) click to toggle source

Loop through all bit-flag values to produce a list of integers

# File lib/search_solr_tools/errors/harvest_error.rb, line 56
def self.code_to_list(code)
  code = code.to_i
  code_list = []

  [128, 64, 32, 16, 8, 4, 2, 1].each do |k|
    if code >= k || code == -1
      code_list.prepend k
      code -= k unless code == -1
    end
  end

  code_list
end
describe_exit_code(code = -1) click to toggle source

If code is -1, it means display all error codes

# File lib/search_solr_tools/errors/harvest_error.rb, line 42
def self.describe_exit_code(code = -1)
  code_list = code_to_list(code)

  codes = {}
  code_list.each do |k|
    next if code == -1 && !ERRCODE_DESC.keys.include?(k) # skip INVALID CODE if showing all codes

    codes[k] = ERRCODE_DESC.keys.include?(k) ? ERRCODE_DESC[k] : 'INVALID CODE NUMBER'
  end

  codes
end
new(status, message = nil) click to toggle source
Calls superclass method
# File lib/search_solr_tools/errors/harvest_error.rb, line 70
def initialize(status, message = nil)
  @status_data = status
  @other_message = message

  super message
end

Public Instance Methods

exit_code() click to toggle source

rubocop:disable Metrics/AbcSize

# File lib/search_solr_tools/errors/harvest_error.rb, line 78
def exit_code
  if @status_data.nil?
    logger.error "OTHER ERROR REPORTED: #{@other_message}"
    return ERRCODE_OTHER
  end

  logger.error "EXIT CODE STATUS:\n#{@status_data.status}"

  code = 0
  code += ERRCODE_SOLR_PING unless @status_data.ping_solr
  code += ERRCODE_SOURCE_PING unless @status_data.ping_source
  code += ERRCODE_SOURCE_NO_RESULTS if @status_data.status[Helpers::HarvestStatus::HARVEST_NO_DOCS].positive?
  code += ERRCODE_SOURCE_HARVEST_ERROR if @status_data.status[Helpers::HarvestStatus::HARVEST_FAILURE].positive?
  code += ERRCODE_DOCUMENT_INVALID if @status_data.status[Helpers::HarvestStatus::INGEST_ERR_INVALID_DOC].positive?
  code += ERRCODE_INGEST_ERROR if @status_data.status[Helpers::HarvestStatus::INGEST_ERR_SOLR_ERROR].positive?

  code = ERRCODE_OTHER if code.zero?

  code
end
message() click to toggle source

rubocop:enable Metrics/AbcSize

# File lib/search_solr_tools/errors/harvest_error.rb, line 100
def message
  self.class.describe_exit_code(exit_code).map { |_c, v| v }.join("\n")
end