Skip to content

Commit

Permalink
save as a custom event the API calls
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed Oct 5, 2024
1 parent 0223052 commit 5afb907
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions lib/ontologies_api_client/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require 'ostruct'
require 'benchmark'
require 'active_support/cache'
require 'rails_performance'
##
# This monkeypatch makes OpenStruct act like Struct objects
class OpenStruct
Expand Down Expand Up @@ -69,14 +70,17 @@ def self.get(path, params = {}, options = {})
begin
response = nil
time = Benchmark.realtime do
response = connection.get do |req|
req.url path
req.params = params.dup
req.options[:timeout] = 60
req.headers.merge(headers)
req.headers[:invalidate_cache] = invalidate_cache
RailsPerformance.measure("Getting: #{path} with #{params} - cache: #{response.headers["X-Rack-Cache"]}", "API Call #{path}") do
response = connection.get do |req|
req.url path
req.params = params.dup
req.options[:timeout] = 60
req.headers.merge(headers)
req.headers[:invalidate_cache] = invalidate_cache
end
end
end

puts "Getting: #{path} with #{params} (t: #{time}s - cache: #{response.headers["X-Rack-Cache"]})" if $DEBUG_API_CLIENT
rescue Exception => e
params = Faraday::Utils.build_query(params)
Expand Down

0 comments on commit 5afb907

Please sign in to comment.