Skip to content

Commit 5908f22

Browse files
committed
STSPG-2386: Dynamic hermes weights
1 parent 04a24c7 commit 5908f22

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/hermes/deliverer.rb

+4-2
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def aggregate_weight_for_type(type, filter: [])
8282
}
8383

8484
# then sum up all of the weights across our providers
85-
providers.map(&:weight).inject(0, :+)
85+
providers.count == 1 ? 1 : providers.map(&:weight).inject(0, :+)
8686
end
8787

8888
def weighted_provider_for_type(type, filter: [])
@@ -99,7 +99,9 @@ def weighted_provider_for_type(type, filter: [])
9999
filter.empty? || filter.include?(provider_instance.class)
100100
}
101101

102-
# if we end up with an empty list we're in troubl
102+
return providers.first if providers.count == 1
103+
104+
# if we end up with an empty list we're in trouble
103105
raise ProviderNotFoundError, "Empty provider list found for type:#{type} filter:#{filter}" unless providers.any?
104106

105107
# get the aggregate weight, and make sure it's more than 0 after the filter

0 commit comments

Comments
 (0)