Skip to content
Snippets Groups Projects
Commit 5c7f3cb6 authored by Paul Millar's avatar Paul Millar
Browse files

update_oai-pmh use standard function to emit logging line

parent 21a17caf
No related branches found
No related tags found
1 merge request!64update_oai-pmh Add a back-off strategy, to allow a service to recover
......@@ -16,26 +16,26 @@ def check_oai_pmh_endpoint(endpoint_url)
response = HTTParty.head(queryIdentify_url)
if !response.success?
puts " Error: Identify response has HTTP status code #{response.code}."
print_with_time("Error: Identify response has HTTP status code #{response.code}.")
return "Error"
end
response = HTTParty.get(queryIdentify_url)
if response.body.nil? || response.body.empty?
puts " Error: Identify response is empty."
print_with_time("Error: Identify response is empty.")
return "Error"
end
xml_response = Nokogiri::XML(response.body)
oai_pmh_tag = xml_response.at_xpath('//*[name()="OAI-PMH"]')
if !oai_pmh_tag
puts " Error: Identify response has no OAI-PMH tag."
print_with_time("Error: Identify response has no OAI-PMH tag.")
return "Error"
end
return "Active"
rescue StandardError => e
puts " Error: Identify request failed: #{e.message}"
print_with_time("Error: Identify request failed: #{e.message}")
return "Error"
end
end
......@@ -72,7 +72,7 @@ def list_sets(endpoint)
end
end
rescue StandardError => e
puts " Error: ListSets request failed: #{e.message}"
print_with_time("Error: ListSets request failed: #{e.message}")
end
return sets_info
end
......@@ -131,7 +131,7 @@ def list_identifiers(url)
if hasServerResponded && attempts == 1
print "\n"
end
print " Attempt #{attempts} of #{MAX_HTTP_GET_RETRIES} failed: #{e.message}\n"
print_with_time("Attempt #{attempts} of #{MAX_HTTP_GET_RETRIES} failed: #{e.message}")
if attempts >= MAX_HTTP_GET_RETRIES
raise StandardError.new "Too many GET requests failed for #{url}"
......@@ -191,6 +191,10 @@ def list_identifiers(url)
return total, set_counts, resumptionToken
end
def print_with_time(text)
print " #{Time.now.strftime("%d/%m/%Y %H:%M:%S")} #{text}\n"
end
def count_identifiers(endpoint, prefix)
url = endpoint + "?verb=ListIdentifiers&metadataPrefix=" + prefix
......@@ -200,7 +204,8 @@ def count_identifiers(endpoint, prefix)
while resumptionToken
if i % 40 == 0
if i > 0
print "\n #{Time.now.strftime("%d/%m/%Y %H:%M:%S")} harvested #{overall_total} records so far.\n"
print("\n")
print_with_time("harvested #{overall_total} records so far.")
end
print " Harvesting: "
end
......@@ -236,7 +241,7 @@ def query_oai_pmh_endpoint(endpoint)
begin
total_count, set_counts = count_identifiers(endpoint, dc_prefix)
rescue StandardError => e
puts " Error: ListIdentifiers failed: #{e.message}"
print_with_time("Error: ListIdentifiers failed: #{e.message}")
total_count = 0
set_counts = {}
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment