mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Change Event#thread_id to #transaction_id. Defaults to one "transaction" per thread but you can explicitly declare the start of a new one. This makes it possible for each request to have it own id.
This commit is contained in:
parent
03d3824d96
commit
c9487ed6af
2 changed files with 31 additions and 12 deletions
|
@ -16,8 +16,8 @@ module ActiveSupport
|
|||
#
|
||||
# @events = []
|
||||
#
|
||||
# ActiveSupport::Notifications.subscribe do |event|
|
||||
# @events << event
|
||||
# ActiveSupport::Notifications.subscribe do |*args|
|
||||
# @events << ActiveSupport::Notifications::Event.new(*args)
|
||||
# end
|
||||
#
|
||||
# ActiveSupport::Notifications.instrument(:render, :extra => :information) do
|
||||
|
@ -25,7 +25,6 @@ module ActiveSupport
|
|||
# end
|
||||
#
|
||||
# event = @events.first
|
||||
# event.class #=> ActiveSupport::Notifications::Event
|
||||
# event.name #=> :render
|
||||
# event.duration #=> 10 (in miliseconds)
|
||||
# event.result #=> "Foo"
|
||||
|
@ -45,7 +44,7 @@ module ActiveSupport
|
|||
mattr_accessor :queue
|
||||
|
||||
class << self
|
||||
delegate :instrument, :transaction_id, :generate_id, :to => :instrumenter
|
||||
delegate :instrument, :transaction_id, :transaction, :to => :instrumenter
|
||||
|
||||
def instrumenter
|
||||
Thread.current[:notifications_instrumeter] ||= Instrumenter.new(publisher)
|
||||
|
@ -118,15 +117,15 @@ module ActiveSupport
|
|||
end
|
||||
|
||||
class Event
|
||||
attr_reader :name, :time, :end, :thread_id, :result, :payload
|
||||
attr_reader :name, :time, :end, :transaction_id, :result, :payload
|
||||
|
||||
def initialize(name, start, ending, result, thread_id, payload)
|
||||
@name = name
|
||||
@payload = payload.dup
|
||||
@time = start
|
||||
@thread_id = thread_id
|
||||
@end = ending
|
||||
@result = result
|
||||
def initialize(name, start, ending, result, transaction_id, payload)
|
||||
@name = name
|
||||
@payload = payload.dup
|
||||
@time = start
|
||||
@transaction_id = transaction_id
|
||||
@end = ending
|
||||
@result = result
|
||||
end
|
||||
|
||||
def duration
|
||||
|
|
|
@ -124,6 +124,26 @@ class NotificationsMainTest < Test::Unit::TestCase
|
|||
assert_equal Hash[:payload => "notifications"], @events.last.payload
|
||||
end
|
||||
|
||||
def test_subscribed_in_a_transaction
|
||||
@another = []
|
||||
|
||||
ActiveSupport::Notifications.subscribe("cache") do |*args|
|
||||
@another << ActiveSupport::Notifications::Event.new(*args)
|
||||
end
|
||||
|
||||
ActiveSupport::Notifications.instrument(:cache){ 1 }
|
||||
ActiveSupport::Notifications.transaction do
|
||||
ActiveSupport::Notifications.instrument(:cache){ 1 }
|
||||
end
|
||||
ActiveSupport::Notifications.instrument(:cache){ 1 }
|
||||
|
||||
sleep 0.1
|
||||
|
||||
before, during, after = @another.map {|e| e.transaction_id }
|
||||
assert_equal before, after
|
||||
assert_not_equal before, during
|
||||
end
|
||||
|
||||
def test_subscriber_with_pattern
|
||||
@another = []
|
||||
|
||||
|
|
Loading…
Reference in a new issue