Skip to content

Commit b278b82

Browse files
committed
Tune #inspect output for Sidekiq::Component and Sidekiq::Config to keep size managable, fixes sidekiq#6553
1 parent a1fb1ee commit b278b82

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

lib/sidekiq/component.rb

+22
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,27 @@ def fire_event(event, options = {})
8181
end
8282
arr.clear if oneshot # once we've fired an event, we never fire it again
8383
end
84+
85+
# When you have a large tree of components, the `inspect` output
86+
# can get out of hand, especially with lots of Sidekiq::Config
87+
# references everywhere. We avoid calling `inspect` on more complex
88+
# state and use `to_s` instead to keep output manageable, #6553
89+
def inspect
90+
"#<#{self.class.name} #{
91+
instance_variables.map do |name|
92+
value = instance_variable_get(name)
93+
case value
94+
when Proc
95+
"#{name}=#{value}"
96+
when Sidekiq::Config
97+
"#{name}=#{value}"
98+
when Sidekiq::Component
99+
"#{name}=#{value}"
100+
else
101+
"#{name}=#{value.inspect}"
102+
end
103+
end.join(", ")
104+
}>"
105+
end
84106
end
85107
end

lib/sidekiq/config.rb

+6
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ def initialize(options = {})
6565
attr_reader :capsules
6666
attr_accessor :thread_priority
6767

68+
def inspect
69+
"#<#{self.class.name} @options=#{
70+
@options.except(:lifecycle_events, :reloader, :death_handlers, :error_handlers).inspect
71+
}>"
72+
end
73+
6874
def to_json(*)
6975
Sidekiq.dump_json(@options)
7076
end

test/config_test.rb

+6
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,10 @@
1616
@config.redis = {size: 3}
1717
assert_equal 3, @config.redis_pool.size
1818
end
19+
20+
it "keeps #inspect output managable" do
21+
assert_operator @config.inspect.size, :<, 500
22+
refute_match(/death_handlers/, @config.inspect)
23+
refute_match(/error_handlers/, @config.inspect)
24+
end
1925
end

0 commit comments

Comments
 (0)