Skip to content

Commit

Permalink
fix: ActiveJob::Handlers.unsubscribe (#1078)
Browse files Browse the repository at this point in the history
Fix ActiveJob::Handlers.unsubscribe
  • Loading branch information
lavoiesl authored Jul 22, 2024
1 parent 246fc10 commit 8b9aba3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def subscribe
# Removes Event Handler Subscriptions for ActiveJob notifications
# @note this method is not thread-safe and should not be used in a multi-threaded context
def unsubscribe
@subscriptions&.each { |subscriber| ActiveSupport::Notifications.unsubscribe(subscriber) }
@subscriptions&.each { |subscriber| ::ActiveSupport::Notifications.unsubscribe(subscriber) }
@subscriptions = nil
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,14 @@
_(MixedArgsJob.perform_now('arg1', 'arg2', keyword2: :keyword2)).must_be_nil # Make sure this runs without raising an error
end
end

describe 'usage' do
it 'can unsubscribe' do
_(OpenTelemetry::Instrumentation::ActiveJob::Handlers.instance_variable_get(:@subscriptions)).wont_be_empty

OpenTelemetry::Instrumentation::ActiveJob::Handlers.unsubscribe

_(OpenTelemetry::Instrumentation::ActiveJob::Handlers.instance_variable_get(:@subscriptions)).must_be_nil
end
end
end

0 comments on commit 8b9aba3

Please sign in to comment.