blazer 1.2.1 → 1.3.0

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.

Potentially problematic release.


This version of blazer might be problematic. Click here for more details.

@@ -79,7 +79,16 @@ module Blazer
79
79
 
80
80
  in_transaction do
81
81
  begin
82
- connection_model.connection.execute("SET statement_timeout = #{timeout.to_i * 1000}") if timeout && (postgresql? || redshift?)
82
+ if timeout
83
+ if postgresql? || redshift?
84
+ connection_model.connection.execute("SET statement_timeout = #{timeout.to_i * 1000}")
85
+ elsif mysql?
86
+ connection_model.connection.execute("SET max_execution_time = #{timeout.to_i * 1000}")
87
+ else
88
+ raise Blazer::TimeoutNotSupported, "Timeout not supported for #{adapter_name} adapter"
89
+ end
90
+ end
91
+
83
92
  result = connection_model.connection.select_all("#{statement} /*#{comment}*/")
84
93
  result.each do |untyped_row|
85
94
  row = {}
@@ -90,7 +99,7 @@ module Blazer
90
99
  end
91
100
  rescue ActiveRecord::StatementInvalid => e
92
101
  error = e.message.sub(/.+ERROR: /, "")
93
- error = Blazer::TIMEOUT_MESSAGE if error.include?("canceling statement due to statement timeout") || error.include?("cancelled on user's request") || error.include?("system requested abort query")
102
+ error = Blazer::TIMEOUT_MESSAGE if Blazer::TIMEOUT_ERRORS.any? { |e| error.include?(e) }
94
103
  end
95
104
  end
96
105
 
@@ -119,23 +128,28 @@ module Blazer
119
128
  end
120
129
 
121
130
  def postgresql?
122
- connection_model.connection.adapter_name == "PostgreSQL"
131
+ ["PostgreSQL", "PostGIS"].include?(adapter_name)
123
132
  end
124
133
 
125
134
  def redshift?
126
- connection_model.connection.adapter_name == "Redshift"
135
+ ["Redshift"].include?(adapter_name)
136
+ end
137
+
138
+ def mysql?
139
+ ["MySQL", "Mysql2", "Mysql2Spatial"].include?(adapter_name)
127
140
  end
128
141
 
129
142
  protected
130
143
 
144
+ def adapter_name
145
+ connection_model.connection.adapter_name
146
+ end
147
+
131
148
  def in_transaction
132
149
  if use_transaction?
133
150
  connection_model.transaction do
134
- begin
135
- yield
136
- ensure
137
- raise ActiveRecord::Rollback
138
- end
151
+ yield
152
+ raise ActiveRecord::Rollback
139
153
  end
140
154
  else
141
155
  yield
@@ -19,7 +19,13 @@ module Blazer
19
19
  Blazer.user_method ||= "current_#{Blazer.user_class.to_s.downcase.singularize}"
20
20
  end
21
21
 
22
- Blazer::Query.belongs_to :creator, class_name: Blazer.user_class.to_s if Blazer.user_class
22
+ Blazer.check_schedules = Blazer.settings["check_schedules"] if Blazer.settings.key?("check_schedules")
23
+
24
+ if Blazer.user_class
25
+ Blazer::Query.belongs_to :creator, class_name: Blazer.user_class.to_s
26
+ Blazer::Dashboard.belongs_to :creator, class_name: Blazer.user_class.to_s
27
+ Blazer::Check.belongs_to :creator, class_name: Blazer.user_class.to_s
28
+ end
23
29
 
24
30
  Blazer.cache ||= Rails.cache
25
31
  end
@@ -1,3 +1,3 @@
1
1
  module Blazer
2
- VERSION = "1.2.1"
2
+ VERSION = "1.3.0"
3
3
  end
@@ -5,7 +5,6 @@ data_sources:
5
5
  url: <%%= ENV["BLAZER_DATABASE_URL"] %>
6
6
 
7
7
  # statement timeout, in seconds
8
- # applies to PostgreSQL only
9
8
  # none by default
10
9
  # timeout: 15
11
10
 
@@ -45,3 +44,8 @@ audit: true
45
44
 
46
45
  # email to send checks from
47
46
  # from_email: blazer@example.org
47
+
48
+ check_schedules:
49
+ - "1 day"
50
+ - "1 hour"
51
+ - "5 minutes"
@@ -18,6 +18,7 @@ class <%= migration_class_name %> < ActiveRecord::Migration
18
18
  end
19
19
 
20
20
  create_table :blazer_dashboards do |t|
21
+ t.refrences :creator
21
22
  t.text :name
22
23
  t.timestamps
23
24
  end
@@ -30,9 +31,13 @@ class <%= migration_class_name %> < ActiveRecord::Migration
30
31
  end
31
32
 
32
33
  create_table :blazer_checks do |t|
34
+ t.references :creator
33
35
  t.references :query
34
36
  t.string :state
37
+ t.string :schedule
35
38
  t.text :emails
39
+ t.boolean :invert
40
+ t.timestamp :last_run_at
36
41
  t.timestamps
37
42
  end
38
43
  end
@@ -1,9 +1,7 @@
1
- require "rake"
2
-
3
1
  namespace :blazer do
4
2
  desc "run checks"
5
- task run_checks: :environment do
6
- Blazer.run_checks
3
+ task :run_checks, [:schedule] => :environment do |t, args|
4
+ Blazer.run_checks(schedule: args[:schedule] || ENV["SCHEDULE"])
7
5
  end
8
6
 
9
7
  task send_failing_checks: :environment do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blazer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-26 00:00:00.000000000 Z
11
+ date: 2016-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -84,6 +84,7 @@ files:
84
84
  - app/assets/fonts/blazer/glyphicons-halflings-regular.ttf
85
85
  - app/assets/fonts/blazer/glyphicons-halflings-regular.woff
86
86
  - app/assets/fonts/blazer/glyphicons-halflings-regular.woff2
87
+ - app/assets/javascripts/blazer/Chart.js
87
88
  - app/assets/javascripts/blazer/Sortable.js
88
89
  - app/assets/javascripts/blazer/ace/ace.js
89
90
  - app/assets/javascripts/blazer/ace/ext-language_tools.js
@@ -135,7 +136,6 @@ files:
135
136
  - app/views/blazer/dashboards/new.html.erb
136
137
  - app/views/blazer/dashboards/show.html.erb
137
138
  - app/views/blazer/queries/_form.html.erb
138
- - app/views/blazer/queries/_index.html.erb
139
139
  - app/views/blazer/queries/_tables.html
140
140
  - app/views/blazer/queries/edit.html.erb
141
141
  - app/views/blazer/queries/home.html.erb
@@ -148,11 +148,11 @@ files:
148
148
  - lib/blazer.rb
149
149
  - lib/blazer/data_source.rb
150
150
  - lib/blazer/engine.rb
151
- - lib/blazer/tasks.rb
152
151
  - lib/blazer/version.rb
153
152
  - lib/generators/blazer/install_generator.rb
154
153
  - lib/generators/blazer/templates/config.yml
155
154
  - lib/generators/blazer/templates/install.rb
155
+ - lib/tasks/blazer.rake
156
156
  homepage: https://github.com/ankane/blazer
157
157
  licenses:
158
158
  - MIT
@@ -1,32 +0,0 @@
1
- <% (@dashboards + @my_queries + @queries).each do |query| %>
2
- <% is_query = query.is_a?(Blazer::Query) %>
3
- <tr>
4
- <td class="query <%= "dashboard" unless is_query %>">
5
- <%= link_to query.name, query %>
6
- <% if is_query %>
7
- <span style="color: #ccc;"><%= extract_vars(query.statement).join(", ") %></span>
8
- <% if @queries.size < 1000 && query.created_at > 2.days.ago %>
9
- <small style="font-weight: bold; color: #5cb85c;">NEW</small>
10
- <% end %>
11
- <% if @trending_queries[query.id] %>
12
- <small style="font-weight: bold; color: #f60;">TRENDING</small>
13
- <% end %>
14
- <% if @checks[query.id] %>
15
- <small style="font-weight: bold; color: #f60;">CHECK</small>
16
- <% end %>
17
- <div class="hide"><%= query.name.gsub(/\s+/, "") %></div>
18
- <% end %>
19
- </td>
20
- <td class="creator text-right text-muted">
21
- <% if query.respond_to?(:creator) && (creator = query.creator) && creator.respond_to?(Blazer.user_name) %>
22
- <% name = creator.send(Blazer.user_name) %>
23
- <% if creator == blazer_user %>
24
- You
25
- <div class="hide">me <%= name %></div>
26
- <% else %>
27
- <%= name %>
28
- <% end %>
29
- <% end %>
30
- </td>
31
- </tr>
32
- <% end %>