rails-autoscale-core 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: aea9f97efeaa39ee58923722220094d45ee721e925064f9f344e442cf839e10b
4
- data.tar.gz: 2eb632696c60647be6af0023e3202007d1ef045f26a07ecc7d84b33db108efc6
3
+ metadata.gz: 03aadf04a101c5dfdaf9a715a25f36d3304943833c4feeba551c11645590418c
4
+ data.tar.gz: 8e46c89f87301ff458ae77640ebf1dad10abf53ffde7110448d4c6c6ffafd5c0
5
5
  SHA512:
6
- metadata.gz: 80b2d814748d4ec90fce53a11f98a22e6ba4c17135798188742ce0b1b8a5a8ed5f4231ced13df03ce19fde892423e965ada294e287696b9d903860c178f562f4
7
- data.tar.gz: d12cde36b76a75f737b1a1aab3e2959ab318e93c461680532905868de7d4a31503e401ae8544d989a2f2a5e3bdef3bd33854711220405ddd5815244ecc51bc52
6
+ metadata.gz: 1a754daf2618a1e9d7a7dadd773b798493ecdbbfc27882231df528170ffa44e159941bd7f52ecf1878df53e50291abd9b00aafbe8938ae3f263aa1accb4fa700
7
+ data.tar.gz: f3b11817285f7afbc3c656419d06f797d75f829ec329cd6a526ec51ea2322fb4a060e3d9fe4c827eb89e03b99fc58999d01f794308d0aead18013b81cbded9db
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: rails-autoscale-core
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: