123456789_123456789_123456789_123456789_123456789_

Class: ActiveRecord::ConnectionAdapters::QueryIntent::EventBuffer

Relationships & Source Files
Inherits: Object
Defined in: activerecord/lib/active_record/connection_adapters/query_intent.rb

Overview

Buffers instrumentation events during background execution for later publishing

Class Method Summary

Instance Method Summary

Constructor Details

.new(intent, instrumenter) ⇒ EventBuffer

[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/query_intent.rb', line 8

def initialize(intent, instrumenter)
  @intent = intent
  @instrumenter = instrumenter
  @events = []
end

Instance Method Details

#flush

[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/query_intent.rb', line 23

def flush
  events, @events = @events, []
  events.each do |event|
    event.payload[:lock_wait] = @intent.lock_wait
    ActiveSupport::Notifications.publish_event(event)
  end
end

#instrument(name, payload = {}, &block)

[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/query_intent.rb', line 14

def instrument(name, payload = {}, &block)
  event = @instrumenter.new_event(name, payload)
  begin
    event.record(&block)
  ensure
    @events << event
  end
end