Skip to content

Commit

Permalink
use directly RailsPerformance::Models::CustomRecord instead of measure
Browse files Browse the repository at this point in the history
syphax-bouazzouni committed Oct 11, 2024

Verified

This commit was signed with the committer’s verified signature.
benesch Nikhil Benesch
1 parent 0f7f15c commit 494c512
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions lib/ontologies_api_client/http.rb
Original file line number Diff line number Diff line change
@@ -69,7 +69,7 @@ def self.get(path, params = {}, options = {})
begin
begin
response = nil
time = monitor_time(path, params, response.headers["X-Rack-Cache"]) do
time = Benchmark.realtime do
response = connection.get do |req|
req.url path
req.params = params.dup
@@ -78,6 +78,8 @@ def self.get(path, params = {}, options = {})
req.headers[:invalidate_cache] = invalidate_cache
end
end

monitor_request(params, path, response, time)
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)
@@ -165,18 +167,17 @@ def self.object_from_json(json)

private

def self.monitor_time(path, params, cache_hit, &block)
Benchmark.realtime do
if defined?(Rails) && RailsPerformance.enabled
RailsPerformance.measure("Getting: #{path} with #{params} - cache: #{cache_hit}", "API Call #{path}") do
block.call
end
else
block.call
end
end
def self.monitor_request(params, path, response, time)
RailsPerformance::Models::CustomRecord.new(
tag_name: "Getting: #{path} with #{params} - cache: (#{response.headers["X-Rack-Cache"]})",
namespace_name: "API call #{path}",
status: response.status,
duration: time,
datetime: Time.current.strftime(RailsPerformance::FORMAT),
datetimei: Time.current.to_i).save if defined?(Rails) && RailsPerformance.enabled
end


def self.custom_req(obj, file, file_attribute, req)
req.headers['Content-Type'] = 'application/json'

0 comments on commit 494c512

Please sign in to comment.