Skip to content

Commit

Permalink
Added a timeout to the ORCID check (#275)
Browse files Browse the repository at this point in the history
* Added a timeout to the ORCID check

* Updated the code to pass the read timeout and the correct syntax

Co-authored-by: Carolyn Cole <[email protected]>

* Remove duplicate stub

---------

Co-authored-by: Carolyn Cole <[email protected]>
  • Loading branch information
hectorcorrea and carolyncole authored Sep 17, 2024
1 parent 0dddeb4 commit 2acab4c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 18 deletions.
15 changes: 11 additions & 4 deletions app/models/orcid_api_status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@
class OrcidApiStatus < HealthMonitor::Providers::Base
def check!
uri = URI("https://api.orcid.org/v3.0/apiStatus")
response = Net::HTTP.get(uri)
json = JSON.parse(response)
if json.values.include?(false)
raise "The ORCID API has an invalid status https://api.orcid.org/v3.0/apiStatus"
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.read_timeout = 2 # seconds
response = http.get(uri.request_uri)
if response.code == "200"
json = JSON.parse(response.body)
if json.values.include?(false)
raise "The ORCID API has an invalid status https://api.orcid.org/v3.0/apiStatus"
end
else
raise "The ORCID API returned HTTP error code: #{response.code}"
end
end
end
13 changes: 0 additions & 13 deletions spec/models/orcid_status_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,6 @@
require "rails_helper"

RSpec.describe OrcidApiStatus, type: :model do
before do
stub_request(:get, "https://api.orcid.org/v3.0/apiStatus")
.with(
headers: {
"Accept" => "*/*",
"Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
"Host" => "api.orcid.org",
"User-Agent" => "Ruby"
}
)
.to_return(status: 200, body: '{"tomcatUp":true,"dbConnectionOk":true,"readOnlyDbConnectionOk":true,"overallOk":true}', headers: {})
end

it "checks the status" do
status = described_class.new
expect { status.check! }.not_to raise_error
Expand Down
1 change: 0 additions & 1 deletion spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@
headers: {
"Accept" => "*/*",
"Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
"Host" => "api.orcid.org",
"User-Agent" => "Ruby"
}
)
Expand Down

0 comments on commit 2acab4c

Please sign in to comment.