Deprecate Event#{children,parent_of}

This commit is contained in:
John Hawthorn 2022-01-17 10:49:31 -08:00
parent 51e28dc322
commit 9f0b8eb584
3 changed files with 20 additions and 25 deletions

View File

@ -1,3 +1,5 @@
* Deprecate `Notification::Event`'s `#children` and `#parent_of?`
* Change default serialization format of `MessageEncryptor` from `Marshal` to `JSON` for Rails 7.1.
Existing apps are provided with an upgrade path to migrate to `JSON` as described in `guides/source/upgrading_ruby_on_rails.md`

View File

@ -56,7 +56,7 @@ module ActiveSupport
end
class Event
attr_reader :name, :time, :end, :transaction_id, :children
attr_reader :name, :time, :end, :transaction_id
attr_accessor :payload
def initialize(name, start, ending, transaction_id, payload)
@ -65,7 +65,6 @@ module ActiveSupport
@time = start ? start.to_f * 1_000.0 : start
@transaction_id = transaction_id
@end = ending ? ending.to_f * 1_000.0 : ending
@children = []
@cpu_time_start = 0.0
@cpu_time_finish = 0.0
@allocation_count_start = 0
@ -117,6 +116,23 @@ module ActiveSupport
@allocation_count_finish - @allocation_count_start
end
def children # :nodoc:
ActiveSupport::Deprecation.warn <<~EOM
ActiveSupport::Notifications::Event#children is deprecated and will
be removed in Rails 7.2.
EOM
[]
end
def parent_of?(event) # :nodoc:
ActiveSupport::Deprecation.warn <<~EOM
ActiveSupport::Notifications::Event#parent_of? is deprecated and will
be removed in Rails 7.2.
EOM
start = (time - event.time) * 1000
start <= 0 && (start + duration >= event.duration)
end
# Returns the difference in milliseconds between when the execution of the
# event started and when it ended.
#
@ -133,14 +149,6 @@ module ActiveSupport
self.end - time
end
def <<(event)
@children << event
end
def parent_of?(event)
@children.include? event
end
private
def now
Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_millisecond)

View File

@ -462,21 +462,6 @@ module Notifications
assert_equal Hash[payload: :bar], event.payload
end
def test_event_is_parent_based_on_children
time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
parent = event(:foo, Process.clock_gettime(Process::CLOCK_MONOTONIC), Process.clock_gettime(Process::CLOCK_MONOTONIC) + 100, random_id, {})
child = event(:foo, time, time + 10, random_id, {})
not_child = event(:foo, time, time + 100, random_id, {})
parent.children << child
assert parent.parent_of?(child)
assert_not child.parent_of?(parent)
assert_not parent.parent_of?(not_child)
assert_not not_child.parent_of?(parent)
end
def test_subscribe_raises_error_on_non_supported_arguments
notifier = ActiveSupport::Notifications::Fanout.new