5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/active_record_stats/resque_plugin.rb', line 5
def around_perform_active_record_stats(*args, &block)
totals = {}
gather_sql = ->(_name, _started_at, _finished_at, _unique_id, payload) {
return if payload[:name] == 'SCHEMA' || payload[:sql].blank?
return unless type = ActiveRecordStats.statement_type(payload[:sql])
totals[type] ||= 0
totals[type] += 1
}
sub = ActiveSupport::Notifications.subscribe('sql.active_record', &gather_sql)
yield
ensure
ActiveSupport::Notifications.unsubscribe(sub)
emit_active_record_stats(name, totals.dup)
end
|