lib/rorvswild.rb in rorvswild-0.1.5 vs lib/rorvswild.rb in rorvswild-0.2.0
- old
+ new
@@ -64,10 +64,11 @@
ActiveSupport::Notifications.subscribe("start_processing.action_controller", &method(:before_http_request))
ActionController::Base.rescue_from(StandardError) { |exception| client.after_exception(exception, self) }
Resque::Job.send(:extend, ResquePlugin) if defined?(Resque::Job)
Delayed::Worker.lifecycle.around(:invoke_job, &method(:around_delayed_job)) if defined?(Delayed::Worker)
+ Sidekiq.configure_server { |config| config.server_middleware { |chain| chain.add(SidekiqPlugin) } } if defined?(Sidekiq)
end
def before_http_request(name, start, finish, id, payload)
@request = {controller: payload[:controller], action: payload[:action], path: payload[:path]}
@queries = []
@@ -204,14 +205,14 @@
def slowest_queries
queries.sort { |h1, h2| h2[:runtime] <=> h1[:runtime] }[0, 25]
end
+ SELECT_REGEX = /\Aselect/i.freeze
+
def explain(sql, binds)
- rows = ActiveRecord::Base.connection.exec_query("EXPLAIN " + sql, "EXPLAIN", binds)
- rows.map { |row| row["QUERY PLAN"] }.join("\n")
- rescue => ex
+ ActiveRecord::Base.connection.explain(sql, binds) if (sql =~ SELECT_REGEX) == 0
end
def post_request(attributes)
post("/requests", request: attributes)
rescue => exception
@@ -303,8 +304,14 @@
end
module ResquePlugin
def around_perform_rorvswild(*args, &block)
RorVsWild.measure_block(to_s + "#perform", &block)
+ end
+ end
+
+ class SidekiqPlugin
+ def call(worker, item, queue, &block)
+ RorVsWild.measure_block(item["class"] + "#perform", &block)
end
end
end