Add instrumentation for slow response processing

pull/944/head
Thibaut Courouble 6 years ago
parent f2faacc50a
commit 9e37ff5c8a

@ -1,5 +1,7 @@
module Docs module Docs
class Requester < Typhoeus::Hydra class Requester < Typhoeus::Hydra
include Instrumentable
attr_reader :request_options attr_reader :request_options
def self.run(urls, options = {}, &block) def self.run(urls, options = {}, &block)
@ -52,9 +54,11 @@ module Docs
end end
def handle_response(response) def handle_response(response)
instrument 'handle_response.requester', url: response.url do
on_response.each do |callback| on_response.each do |callback|
result = callback.call(response) result = callback.call(response)
result.each { |url| request(url) } if result.is_a? Array result.each { |url| request(url) } if result.is_a?(Array)
end
end end
end end
end end

@ -0,0 +1,13 @@
# frozen_string_literal: true
module Docs
class RequesterSubscriber < Subscriber
self.namespace = 'requester'
def handle_response(event)
if event.duration > 10_000
log "WARN: #{format_url event.payload[:url]} was slow to process (#{(event.duration / 1000).round}s)"
end
end
end
end

@ -62,7 +62,7 @@ class DocsCLI < Thor
Docs.rescue_errors = true Docs.rescue_errors = true
Docs.install_report :store if options[:verbose] Docs.install_report :store if options[:verbose]
Docs.install_report :scraper if options[:debug] Docs.install_report :scraper if options[:debug]
Docs.install_report :progress_bar, :doc, :image if $stdout.tty? Docs.install_report :progress_bar, :doc, :image, :requester if $stdout.tty?
require 'unix_utils' if options[:package] require 'unix_utils' if options[:package]

Loading…
Cancel
Save