judoscale-ruby 1.5.1 → 1.5.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 34e63423106d499e2a555bf9343d38224e1eeb1e4f2fa2177d532ff33df3de81
4
- data.tar.gz: 7efed4c6de8f587dac09c10ede982a67f73aba88e6ffeb3275db19dc968f1df7
3
+ metadata.gz: a50732023524ca7f75f8a387dfde1cbd6080a43dbd102b45e2a6d0ab38a25e77
4
+ data.tar.gz: 82e3711577f958ffec7e5f9d8f56532381c1b3f56580c3657cda358028e6a01e
5
5
  SHA512:
6
- metadata.gz: 2858316d5ec92aaca9b448a30699fb64dae7a970a97bf3bd4e54437d5ed5877782efd2b2c698e7c45e5f1c122b652c6463d26e98349c248cf580869bea974aa6
7
- data.tar.gz: 659d23cad27612aff9c3653890758a40a315eaea4e3d319cbb0d36ada38568a00168e13601220ef06dcec7ed49dec325accd1fb844924665e031d7e32bfd4fa4
6
+ metadata.gz: 882aa3493ddf82b6af7c2a87700ada4f77a2b7f194cfc5663ff8b01da52ed2d088f820c611511f5642646d2f1be448f66d7bb7cfb416c6de7a6209f931e8212f
7
+ data.tar.gz: 30fa41c0e79a84c550dd6b9802167965b2650a73c97e3426576c9794dc743fd7a2000d08e919d4a5aa7132cbdc698c89bec99b4a105583a99c32966ae99fab60
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- judoscale-ruby (1.5.1)
4
+ judoscale-ruby (1.5.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -12,6 +12,13 @@ module Judoscale
12
12
  sql
13
13
  end
14
14
 
15
+ # This will respect a multiple-database setup, unlike the `table_exists?` method.
16
+ def self.table_exists_for_model?(model)
17
+ model.connection.schema_cache.data_source_exists?(model.table_name)
18
+ rescue ActiveRecord::NoDatabaseError
19
+ false
20
+ end
21
+
15
22
  def self.table_exists?(table_name)
16
23
  ::ActiveRecord::Base.connection.table_exists?(table_name)
17
24
  rescue ActiveRecord::NoDatabaseError
@@ -4,8 +4,9 @@ module Judoscale
4
4
  class MetricsCollector
5
5
  def self.collect?(config)
6
6
  in_rake_task = defined?(::Rake) && Rake.respond_to?(:application) && Rake.application.top_level_tasks.any?
7
+ in_generator = defined?(::Rails::Command::GenerateCommand)
7
8
 
8
- !in_rake_task || in_whitelisted_rake_tasks?(config.allow_rake_tasks)
9
+ !in_generator && (!in_rake_task || in_whitelisted_rake_tasks?(config.allow_rake_tasks))
9
10
  end
10
11
 
11
12
  def collect
@@ -25,19 +25,20 @@ module Judoscale
25
25
  end
26
26
 
27
27
  enabled_adapters, skipped_adapters = adapters.partition { |adapter|
28
- # judoscale-ruby adapter does not have a metrics collector
29
- adapter.metrics_collector.nil? || adapter.metrics_collector.collect?(config)
28
+ if adapter.metrics_collector&.collect?(config)
29
+ adapter.enabled = true
30
+ end
30
31
  }
31
32
  metrics_collectors_classes = enabled_adapters.map(&:metrics_collector)
32
- metrics_collectors_classes.compact!
33
+ adapters_msg = enabled_adapters.map(&:identifier).concat(
34
+ skipped_adapters.map { |adapter| "#{adapter.identifier}[skipped]" }
35
+ ).join(", ")
33
36
 
34
37
  if metrics_collectors_classes.empty?
35
- adapters_msg = skipped_adapters.map(&:identifier).join(", ")
36
38
  logger.debug "No metrics need to be collected (adapters: #{adapters_msg})"
37
39
  return
38
40
  end
39
41
 
40
- adapters_msg = enabled_adapters.map(&:identifier).join(", ")
41
42
  logger.info "Reporter starting, will report every ~#{config.report_interval_seconds} seconds (adapters: #{adapters_msg})"
42
43
 
43
44
  metrics_collectors = metrics_collectors_classes.map(&:new)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Judoscale
4
- VERSION = "1.5.1"
4
+ VERSION = "1.5.2"
5
5
  end
@@ -20,9 +20,18 @@ module Judoscale
20
20
  attr_reader :adapters
21
21
  end
22
22
 
23
- Adapter = Struct.new(:identifier, :adapter_info, :metrics_collector) do
23
+ class Adapter < Struct.new(:identifier, :adapter_info, :metrics_collector)
24
+ attr_accessor :enabled
25
+
26
+ def initialize(identifier, adapter_info, metrics_collector)
27
+ super
28
+ self.enabled = false
29
+ end
30
+
24
31
  def as_json
25
- {identifier => adapter_info}
32
+ {
33
+ identifier => adapter_info.merge(enabled: enabled)
34
+ }
26
35
  end
27
36
  end
28
37
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: judoscale-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.1
4
+ version: 1.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam McCrea
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2023-08-09 00:00:00.000000000 Z
13
+ date: 2023-08-10 00:00:00.000000000 Z
14
14
  dependencies: []
15
15
  description:
16
16
  email: