Skip to content

Commit

Permalink
audit_results: refactor workflow reporting methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ndushay committed Feb 3, 2020
1 parent 0d518d6 commit cee8162
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions app/services/audit_results.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,22 +150,22 @@ def remove_db_updated_results
# result1 = {response_code => msg}
# result2 = {response_code => msg}
def report_results(logger=Rails.logger)
candidate_workflow_results = []
workflow_results = []
result_array.each do |r|
log_result(r, logger)
if r.key?(INVALID_MOAB)
# Temporary fix for workflow-service throwing exceptions
# because some error reports from MoabReplicationAudit are too long
msg = "#{workflows_msg_prefix} || #{r.values.first}"
msg = "#{string_prefix} || #{r.values.first}"
WorkflowReporter.report_error(druid, actual_version, 'moab-valid', msg)
elsif status_changed_to_ok?(r)
WorkflowReporter.report_completed(druid, actual_version, 'preservation-audit')
elsif WORKFLOW_REPORT_CODES.include?(r.keys.first)
candidate_workflow_results << r
workflow_results << r
end
send_honeybadger_notification(r) if HONEYBADGER_REPORT_CODES.include?(r.keys.first)
end
report_errors_to_workflows(candidate_workflow_results)
report_errors_to_workflows(workflow_results)
result_array
end

Expand All @@ -187,10 +187,9 @@ def result_hash(code, msg_args=nil)
{ code => result_code_msg(code, msg_args) }
end

def report_errors_to_workflows(candidate_workflow_results)
return if candidate_workflow_results.empty?
msg = "#{workflows_msg_prefix} #{candidate_workflow_results.map(&:values).flatten.join(' && ')}"
WorkflowReporter.report_error(druid, actual_version, 'preservation-audit', msg)
def report_errors_to_workflows(error_results)
return if error_results.empty?
WorkflowReporter.report_error(druid, actual_version, 'preservation-audit', results_as_string(error_results))
end

def log_result(result, logger)
Expand All @@ -216,8 +215,12 @@ def log_msg_prefix
@log_msg_prefix ||= "#{check_name}(#{druid}, #{moab_storage_root&.name})"
end

def workflows_msg_prefix
@workflows_msg_prefix ||= begin
def results_as_string(error_results)
@results_as_string ||= "#{string_prefix} #{error_results.map(&:values).flatten.join(' && ')}"
end

def string_prefix
@string_prefix ||= begin
location_info = "actual location: #{moab_storage_root.name}" if moab_storage_root
actual_version_info = "actual version: #{actual_version}" if actual_version
"#{check_name} (#{location_info}; #{actual_version_info})"
Expand Down

0 comments on commit cee8162

Please sign in to comment.