Skip to content

Commit 135c5ed

Browse files
Merge pull request #29 from ontoportal-lirmm/master
Merge master to development
2 parents 2ade126 + 1d8e1b2 commit 135c5ed

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

lib/ontologies_api_client/http.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def self.get(path, params = {}, options = {})
7777
req.headers[:invalidate_cache] = invalidate_cache
7878
end
7979
end
80-
puts "Getting: #{path} with #{params} (t: #{time}s - cache: #{response.headers["X-Rack-Cache"]})" if $DEBUG_API_CLIENT
80+
log "Getting: #{path} with #{params} (t: #{time}s - cache: #{response.headers["X-Rack-Cache"]})" if $DEBUG_API_CLIENT
8181
rescue Exception => e
8282
params = Faraday::Utils.build_query(params)
8383
path << "?" unless params.empty? || path.include?("?")
@@ -95,7 +95,7 @@ def self.get(path, params = {}, options = {})
9595
obj = recursive_struct(load_json(response.body))
9696
end
9797
rescue StandardError => e
98-
puts "Problem getting #{path}" if $DEBUG_API_CLIENT
98+
log "Problem getting #{path}"
9999
raise e
100100
end
101101
obj
@@ -151,7 +151,7 @@ def self.patch(path, obj)
151151
end
152152

153153
def self.delete(id)
154-
puts "Deleting #{id}" if $DEBUG_API_CLIENT
154+
log "Deleting #{id}" if $DEBUG_API_CLIENT
155155
response = conn.delete id
156156
raise StandardError, response.body if response.status >= 500
157157

@@ -162,6 +162,9 @@ def self.object_from_json(json)
162162
recursive_struct(load_json(json))
163163
end
164164

165+
def self.log(message)
166+
puts message if $DEBUG_API_CLIENT
167+
end
165168
private
166169

167170
def self.custom_req(obj, file, file_attribute, req)

lib/ontologies_api_client/request_federation.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def federated_get(params = {}, &link)
2222
end
2323

2424
unless portal_status
25+
HTTP.log("Error in federation #{portal_name} is down status cached for 10 minutes")
2526
next [OpenStruct.new(errors: "Problem retrieving #{portal_name}")]
2627
end
2728

@@ -30,7 +31,8 @@ def federated_get(params = {}, &link)
3031
portal_params = params[portal_name.to_s.downcase] || params
3132
HTTP.get(link.call(conn.url_prefix.to_s.chomp('/')), portal_params, connection: conn)
3233
rescue Exception => e
33-
Rails.cache.write("federation_portal_up_#{portal_name}", false, expires_in: 10.minutes)
34+
HTTP.log("Error in federation #{portal_name} is down status cached for 10 minutes")
35+
Rails.cache.write("federation_portal_up_#{portal_name}", false, expires_in: 10.minutes) unless internal_call?(conn)
3436
[OpenStruct.new(errors: "Problem retrieving #{link.call(conn.url_prefix.to_s.chomp('/')) || conn.url_prefix}")]
3537
end
3638
end
@@ -60,6 +62,9 @@ def request_portals(params = {})
6062
portals
6163
end
6264

65+
def internal_call?(conn)
66+
conn.url_prefix.to_s.start_with?(LinkedData::Client::HTTP.conn.url_prefix.to_s)
67+
end
6368

6469
def portal_name_from_id(id)
6570
LinkedData::Client::HTTP.federated_conn.find { |_, value| value.url_prefix.to_s.eql?(id) }&.first || ''

0 commit comments

Comments
 (0)