ros-apartment 4.0.0.alpha4 → 4.0.0.alpha5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/apartment/pool_observer.rb +12 -1
- data/lib/apartment/tenant.rb +16 -4
- data/lib/apartment/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c4e597c986618a8043acbecc8081ef0399493c545fd3720d8f57653da90025da
|
|
4
|
+
data.tar.gz: 9fb0d04fe5abb04e93a4ef654edc14744dfc8d86d35f6d6ef8b685d7eb6ddb29
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 747e6efe4c8c073368684944bbee84cccfd0b063f389d7b4a699debd97662496db9ea220e6be6f119986fa76e3586d180bb3f61ff61c4c44bc3acc37b7784f0c
|
|
7
|
+
data.tar.gz: 9ceef5927c8169dc2db2041fbbfba99b81c7106a9cf02814812550c1775cd2566398dd8383e78bd0d24e7a82a845d2c4418bc974c43cc5e0169cd25a6072eba5
|
|
@@ -24,7 +24,18 @@ module Apartment
|
|
|
24
24
|
def self.install!(sink:, sample_interval: nil, backend_count: nil)
|
|
25
25
|
observer = new(sink: sink, backend_count: backend_count)
|
|
26
26
|
observer.subscribe!
|
|
27
|
-
|
|
27
|
+
if sample_interval.nil?
|
|
28
|
+
# nil is the intentional "no gauge sampler" signal; counters still flow.
|
|
29
|
+
elsif sample_interval.positive?
|
|
30
|
+
observer.start_sampler!(interval: sample_interval)
|
|
31
|
+
else
|
|
32
|
+
# A non-nil, non-positive interval is almost always a misconfig (e.g. an
|
|
33
|
+
# empty APARTMENT_POOL_SAMPLE_INTERVAL coerced to 0). Silently skipping
|
|
34
|
+
# the sampler ships an observer whose gauges never emit; surface it.
|
|
35
|
+
warn "[Apartment::PoolObserver] sample_interval=#{sample_interval.inspect} is not " \
|
|
36
|
+
'positive; gauge sampler not started (tenant_pools_live/backend_connections ' \
|
|
37
|
+
'will not emit). Pass a positive interval, or nil to disable the sampler.'
|
|
38
|
+
end
|
|
28
39
|
observer
|
|
29
40
|
rescue StandardError
|
|
30
41
|
# Don't leak subscriptions if a later step (e.g. a bad sample_interval)
|
data/lib/apartment/tenant.rb
CHANGED
|
@@ -200,17 +200,29 @@ module Apartment
|
|
|
200
200
|
# it drops EVERY connection leased to the current execution context, across
|
|
201
201
|
# all pools and roles, not just the tenant pool. Do NOT use it inside an
|
|
202
202
|
# outer ActiveRecord::Base.transaction, or while holding a non-tenant
|
|
203
|
-
# connection you mean to keep. Fail-fast:
|
|
204
|
-
# tenant is
|
|
203
|
+
# connection you mean to keep. Fail-fast: a raising block still aborts the
|
|
204
|
+
# fan-out, but the failing tenant's connection is released first — the
|
|
205
|
+
# release is best-effort cleanup (in an ensure), not iteration semantics.
|
|
205
206
|
def each(tenants = nil, release_connection: false)
|
|
206
207
|
raise(ArgumentError, 'Apartment::Tenant.each requires a block') unless block_given?
|
|
207
208
|
|
|
208
209
|
tenants ||= Apartment.tenant_names
|
|
209
210
|
tenants.each do |tenant|
|
|
210
211
|
switch(tenant) { yield(tenant) }
|
|
212
|
+
ensure
|
|
211
213
|
# Handler-wide (:all) covers writing + reading roles — the gem's
|
|
212
|
-
# established release call (see memory_stability_spec).
|
|
213
|
-
|
|
214
|
+
# established release call (see memory_stability_spec). In an ensure so
|
|
215
|
+
# a raising tenant is still released; the exception then propagates and
|
|
216
|
+
# halts the fan-out (fail-fast preserved). Best-effort: a release
|
|
217
|
+
# failure must never mask the block's exception, so it is rescued and
|
|
218
|
+
# warned rather than raised out of the ensure.
|
|
219
|
+
if release_connection
|
|
220
|
+
begin
|
|
221
|
+
ActiveRecord::Base.connection_handler.clear_active_connections!(:all)
|
|
222
|
+
rescue StandardError => e
|
|
223
|
+
warn("[Apartment::Tenant.each] connection release failed: #{e.class}: #{e.message}")
|
|
224
|
+
end
|
|
225
|
+
end
|
|
214
226
|
end
|
|
215
227
|
end
|
|
216
228
|
|
data/lib/apartment/version.rb
CHANGED