Module: Blazer

Defined in:
lib/blazer.rb,
lib/blazer/engine.rb,
lib/blazer/version.rb,
lib/blazer/data_source.rb,
app/models/blazer/audit.rb,
app/models/blazer/check.rb,
app/models/blazer/query.rb,
app/models/blazer/dashboard.rb,
app/models/blazer/connection.rb,
app/helpers/blazer/base_helper.rb,
app/mailers/blazer/check_mailer.rb,
app/models/blazer/dashboard_query.rb,
app/controllers/blazer/base_controller.rb,
lib/generators/blazer/install_generator.rb,
app/controllers/blazer/checks_controller.rb,
app/controllers/blazer/queries_controller.rb,
app/controllers/blazer/dashboards_controller.rb

Defined Under Namespace

Modules: BaseHelper, Generators Classes: Audit, BaseController, Check, CheckMailer, ChecksController, Connection, Dashboard, DashboardQuery, DashboardsController, DataSource, Engine, QueriesController, Query

Constant Summary collapse

VERSION =
"1.0.3"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.auditObject

Returns the value of attribute audit.



10
11
12
# File 'lib/blazer.rb', line 10

def audit
  @audit
end

.cacheObject

Returns the value of attribute cache.



16
17
18
# File 'lib/blazer.rb', line 16

def cache
  @cache
end

.from_emailObject

Returns the value of attribute from_email.



15
16
17
# File 'lib/blazer.rb', line 15

def from_email
  @from_email
end

.time_zoneObject

Returns the value of attribute time_zone.



11
12
13
# File 'lib/blazer.rb', line 11

def time_zone
  @time_zone
end

.transform_statementObject

Returns the value of attribute transform_statement.



17
18
19
# File 'lib/blazer.rb', line 17

def transform_statement
  @transform_statement
end

.user_classObject

Returns the value of attribute user_class.



13
14
15
# File 'lib/blazer.rb', line 13

def user_class
  @user_class
end

.user_methodObject

Returns the value of attribute user_method.



14
15
16
# File 'lib/blazer.rb', line 14

def user_method
  @user_method
end

.user_nameObject

Returns the value of attribute user_name.



12
13
14
# File 'lib/blazer.rb', line 12

def user_name
  @user_name
end

Class Method Details

.data_sourcesObject



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/blazer.rb', line 37

def self.data_sources
  @data_sources ||= begin
    ds = Hash[
      settings["data_sources"].map do |id, s|
        [id, Blazer::DataSource.new(id, s)]
      end
    ]
    ds.default = ds.values.first
    ds
  end
end

.run_checksObject



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/blazer.rb', line 49

def self.run_checks
  Blazer::Check.includes(:query).find_each do |check|
    rows = nil
    error = nil
    tries = 0
    # try 3 times on timeout errors
    begin
      rows, error, cached_at = data_sources[check.query.data_source].run_statement(check.query.statement, refresh_cache: true)
      tries += 1
    end while error && error.include?("canceling statement due to statement timeout") && tries < 3
    check.update_state(rows, error)
  end
end

.send_failing_checksObject



63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/blazer.rb', line 63

def self.send_failing_checks
  emails = {}
  Blazer::Check.includes(:query).where(state: %w[failing error]).find_each do |check|
    check.split_emails.each do |email|
      (emails[email] ||= []) << check
    end
  end

  emails.each do |email, checks|
    Blazer::CheckMailer.failing_checks(email, checks).deliver_later
  end
end

.settingsObject



26
27
28
29
30
31
32
33
34
35
# File 'lib/blazer.rb', line 26

def self.settings
  @settings ||= begin
    path = Rails.root.join("config", "blazer.yml").to_s
    if File.exist?(path)
      YAML.load(ERB.new(File.read(path)).result)
    else
      {}
    end
  end
end