Skip to content

Commit

Permalink
fix: Fail silently when DB or table is missing (#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamlogic committed May 30, 2023
1 parent 9e7bfaa commit 4e1cab6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ def self.adapter_config
Judoscale::Config.instance.delayed_job
end

def self.collect?(config)
super && ActiveRecordHelper.table_exists?("delayed_jobs")
end

def collect
metrics = []
t = Time.now.utc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ def self.adapter_config
Judoscale::Config.instance.good_job
end

def self.collect?(config)
super && ActiveRecordHelper.table_exists?("good_jobs")
end

def initialize
super

Expand Down
4 changes: 4 additions & 0 deletions judoscale-que/lib/judoscale/que/metrics_collector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ def self.adapter_config
Judoscale::Config.instance.que
end

def self.collect?(config)
super && ActiveRecordHelper.table_exists?("que_jobs")
end

def collect
metrics = []
t = Time.now.utc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ def self.cleanse_sql(sql)
sql
end

def self.table_exists?(table_name)
::ActiveRecord::Base.connection.table_exists?(table_name)
rescue ActiveRecord::NoDatabaseError
false
end

private

def run_silently(&block)
Expand Down

0 comments on commit 4e1cab6

Please sign in to comment.