Skip to content

Commit

Permalink
Sleep 10 minutes between retries. Really abort if server fails
Browse files Browse the repository at this point in the history
  • Loading branch information
ngiger committed Nov 10, 2014
1 parent 85b4a8b commit 7374257
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/plugin/medreg_doctor.rb
Expand Up @@ -90,7 +90,7 @@ def update
get_detail_to_glns(saved.size > 0 ? saved : @glns_to_import)
return @doctors_created, @doctors_updated, @doctors_deleted, @doctors_skipped
ensure
File.open(Personen_YAML, 'w+') {|f| f.write(@@all_doctors.to_yaml) }
File.open(Personen_YAML, 'w+') {|f| f.write(@@all_doctors.to_yaml) }
save_for_log "Saved #{@@all_doctors.size} doctors in #{Personen_YAML}"
end

Expand Down Expand Up @@ -123,7 +123,7 @@ def parse_details(doc, gln, info)
specialities = []
(idx_titel+1).upto(idx_privat-1).each{
|j|
line = doc.xpath("//tr")[j].text ;
line = doc.xpath("//tr")[j].text ;
unless line.match(/Keine Angaben vorhanden/)
specialities << line.match(/(.*)\s+(\d+)\s+(\w+)/)[1..3].join(',').gsub("\r","").strip
end
Expand All @@ -133,7 +133,7 @@ def parse_details(doc, gln, info)
(idx_privat+1).upto(99).each{
|j|
next unless doc.xpath("//tr")[j]
line = doc.xpath("//tr")[j].text ;
line = doc.xpath("//tr")[j].text ;
unless line.match(/Keine Angaben vorhanden/)
if m = line.match(/(.*)\s+(\d+)\s+(\w+)/)
experiences << m[1..3].join(',').gsub("\r","").strip
Expand Down Expand Up @@ -226,8 +226,10 @@ def get_detail_to_glns(glns)
rescue Mechanize::ResponseCodeError
nr_retries += 1
log "rescue Mechanize::ResponseCodeError #{gln.inspect}. nr_retries #{nr_retries}"
sleep(10 * 60) # wait 10 minutes till medreg server is back again
end
end
raise "Max retries #{nr_retries} for #{gln.to_s} reached. Aborting import"
}
r_loop.finished
ensure
Expand Down Expand Up @@ -265,11 +267,11 @@ def get_detail_info(info, doc)
address.additional_lines << line if line.length > 0
end
}
addresses << address
addresses << address
}
addresses
end
def get_latest_file
def get_latest_file
agent = Mechanize.new
latest = File.join @archive, "doctors_latest.xlsx"
target = File.join @archive, Time.now.strftime("doctors_%Y.%m.%d.xlsx")
Expand Down Expand Up @@ -340,7 +342,7 @@ def store_doctor(hash)
end
doc_hash.store(key, value)
end

}
@app.update(pointer, doc_hash)
log "store_doctor #{hash[:ean13]} #{action} in database. pointer #{pointer.inspect}. Have now #{@app.doctors.size} doctors. hash #{doc_hash}"
Expand Down

0 comments on commit 7374257

Please sign in to comment.