rails-pulse 0.4.7 → 0.5.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.
- data/README.textile +9 -4
- data/lib/pulse/controller.rb +66 -13
- data/lib/pulse/helper.rb +2 -0
- data/lib/pulse/routes.rb +4 -3
- metadata +39 -54
data/README.textile
CHANGED
@@ -6,11 +6,12 @@ h3. Authors
|
|
6
6
|
|
7
7
|
* "Paul Gross":http://www.prgs.net
|
8
8
|
* "Jesse Newland":http://jnewland.com
|
9
|
+
* "Josh Nichols":http://technicalpickles.com
|
9
10
|
|
10
11
|
h2. Requirements
|
11
12
|
|
12
13
|
* Rails
|
13
|
-
* MySQL, Postgres, or
|
14
|
+
* MySQL, Postgres, or sqlite
|
14
15
|
|
15
16
|
h2. Installation
|
16
17
|
|
@@ -28,7 +29,9 @@ In your @config/routes.rb@:
|
|
28
29
|
|
29
30
|
<pre>
|
30
31
|
<code>
|
31
|
-
pulse
|
32
|
+
pulse
|
33
|
+
# or customize the URL
|
34
|
+
pulse '/admin/pulse'
|
32
35
|
</code>
|
33
36
|
</pre>
|
34
37
|
|
@@ -56,7 +59,9 @@ Finally, add a route to config/routes.rb:
|
|
56
59
|
|
57
60
|
<pre>
|
58
61
|
<code>
|
59
|
-
map.pulse
|
62
|
+
map.pulse
|
63
|
+
# or customize the URL
|
64
|
+
map.pulse '/admin/pulse'
|
60
65
|
</code>
|
61
66
|
</pre>
|
62
67
|
|
@@ -124,4 +129,4 @@ For a complete god configuration example, check out my "god_examples project":ht
|
|
124
129
|
|
125
130
|
h2. License
|
126
131
|
|
127
|
-
Released under "Ruby's license":http://www.ruby-lang.org/en/LICENSE.txt
|
132
|
+
Released under "Ruby's license":http://www.ruby-lang.org/en/LICENSE.txt
|
data/lib/pulse/controller.rb
CHANGED
@@ -1,25 +1,78 @@
|
|
1
1
|
class PulseController < ActionController::Base
|
2
2
|
session :off unless Rails::VERSION::STRING >= "2.3"
|
3
|
-
|
4
|
-
# we don't need pulse cluttering up our new relic stats
|
5
|
-
newrelic_ignore if respond_to?(:newrelic_ignore)
|
6
3
|
|
7
|
-
#The pulse action. Runs <tt>select 1</tt> on the DB. If a sane result is
|
8
|
-
#returned, 'OK' is displayed and a 200 response code is returned. If not,
|
9
|
-
#'ERROR' is returned along with a 500 response code.
|
4
|
+
# The pulse action. Runs <tt>select 1</tt> on the DB. If a sane result is
|
5
|
+
# returned, 'OK' is displayed and a 200 response code is returned. If not,
|
6
|
+
# 'ERROR' is returned along with a 500 response code.
|
10
7
|
def pulse
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
8
|
+
adapter = ActiveRecord::Base::connection_pool.spec.config[:adapter]
|
9
|
+
|
10
|
+
health_method = "#{adapter}_healthy?"
|
11
|
+
activerecord_okay = if respond_to?(health_method)
|
12
|
+
send(health_method)
|
13
|
+
else
|
14
|
+
raise "Don't know how to check #{adapter}... please to fix?"
|
15
|
+
end
|
16
|
+
|
17
|
+
if activerecord_okay
|
18
|
+
render :text => okay_response
|
16
19
|
else
|
17
|
-
render :text =>
|
20
|
+
render :text => error_response, :status => :internal_server_error
|
18
21
|
end
|
19
22
|
end
|
20
23
|
|
21
|
-
|
24
|
+
protected
|
25
|
+
|
26
|
+
# cancel out loggin for the PulseController by defining logger as <tt>nil</tt>
|
22
27
|
def logger
|
23
28
|
nil
|
24
29
|
end
|
30
|
+
|
31
|
+
def sqlite3_healthy?
|
32
|
+
select_one_count == 1
|
33
|
+
end
|
34
|
+
|
35
|
+
def mysql_healthy?
|
36
|
+
select_one_from_dual_num_rows == 1
|
37
|
+
end
|
38
|
+
|
39
|
+
def mysql2_healthy?
|
40
|
+
select_one_from_dual_count == 1
|
41
|
+
end
|
42
|
+
|
43
|
+
def postgresql_healthy?
|
44
|
+
select_one_count == 1
|
45
|
+
end
|
46
|
+
|
47
|
+
def select_one_count
|
48
|
+
count = begin
|
49
|
+
ActiveRecord::Base.connection.execute("select 1").count
|
50
|
+
rescue
|
51
|
+
0
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def select_one_from_dual_count
|
56
|
+
begin
|
57
|
+
ActiveRecord::Base.connection.execute("select 1 from dual").count
|
58
|
+
rescue
|
59
|
+
0
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def select_one_from_dual_num_rows
|
64
|
+
begin
|
65
|
+
ActiveRecord::Base.connection.execute("select 1 from dual").num_rows
|
66
|
+
rescue
|
67
|
+
0
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def okay_response
|
72
|
+
"<html><body>OK #{Time.now.utc.to_s(:db)}</body></html>"
|
73
|
+
end
|
74
|
+
|
75
|
+
def error_response
|
76
|
+
'<html><body>ERROR</body></html>'
|
77
|
+
end
|
25
78
|
end
|
data/lib/pulse/helper.rb
CHANGED
data/lib/pulse/routes.rb
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
module Pulse
|
2
2
|
module Routes
|
3
|
-
def pulse(path)
|
3
|
+
def pulse(path = nil)
|
4
|
+
path ||= "/pulse"
|
4
5
|
if Rails::VERSION::MAJOR == 2
|
5
6
|
connect path, :controller => 'pulse', :action => 'pulse'
|
6
7
|
else
|
7
|
-
|
8
|
+
get path => 'pulse#pulse'
|
8
9
|
end
|
9
10
|
end
|
10
11
|
end
|
11
12
|
end
|
12
13
|
|
13
|
-
if Rails::VERSION::MAJOR
|
14
|
+
if Rails::VERSION::MAJOR > 2
|
14
15
|
ActionDispatch::Routing::Mapper.send :include, Pulse::Routes
|
15
16
|
else # fallback to 2.x stuff
|
16
17
|
ActionController::Routing::RouteSet::Mapper.send :include, Pulse::Routes
|
metadata
CHANGED
@@ -1,51 +1,45 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-pulse
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.0
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 4
|
9
|
-
- 7
|
10
|
-
version: 0.4.7
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Paul Gross
|
14
9
|
- Jesse Newland
|
15
10
|
- Josh Goebel
|
16
11
|
- Will Farrington
|
12
|
+
- Josh Nichols
|
17
13
|
autorequire:
|
18
14
|
bindir: bin
|
19
15
|
cert_chain: []
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
dependencies:
|
24
|
-
- !ruby/object:Gem::Dependency
|
16
|
+
date: 2013-04-01 00:00:00.000000000 Z
|
17
|
+
dependencies:
|
18
|
+
- !ruby/object:Gem::Dependency
|
25
19
|
name: rails
|
26
|
-
|
27
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
requirement: !ruby/object:Gem::Requirement
|
28
21
|
none: false
|
29
|
-
requirements:
|
30
|
-
- -
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
|
33
|
-
segments:
|
34
|
-
- 0
|
35
|
-
version: "0"
|
22
|
+
requirements:
|
23
|
+
- - ! '>='
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: '0'
|
36
26
|
type: :runtime
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
27
|
+
prerelease: false
|
28
|
+
version_requirements: !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
description: ! 'Adds a pulse URL that pings the DB to a Rails app.
|
35
|
+
|
36
|
+
This is the maintained version of the `pulse` gem.'
|
41
37
|
email: jnewland@gmail.com
|
42
38
|
executables: []
|
43
|
-
|
44
39
|
extensions: []
|
45
|
-
|
46
|
-
extra_rdoc_files:
|
40
|
+
extra_rdoc_files:
|
47
41
|
- README.textile
|
48
|
-
files:
|
42
|
+
files:
|
49
43
|
- README.textile
|
50
44
|
- lib/pulse/controller.rb
|
51
45
|
- lib/pulse/helper.rb
|
@@ -54,41 +48,32 @@ files:
|
|
54
48
|
- spec/pulse_spec.rb
|
55
49
|
- spec/spec.opts
|
56
50
|
- spec/spec_helper.rb
|
57
|
-
has_rdoc: false
|
58
51
|
homepage: http://github.com/jnewland/pulse
|
59
52
|
licenses: []
|
60
|
-
|
61
53
|
post_install_message:
|
62
54
|
rdoc_options: []
|
63
|
-
|
64
|
-
require_paths:
|
55
|
+
require_paths:
|
65
56
|
- lib
|
66
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
58
|
none: false
|
68
|
-
requirements:
|
69
|
-
- -
|
70
|
-
- !ruby/object:Gem::Version
|
71
|
-
|
72
|
-
|
73
|
-
- 0
|
74
|
-
version: "0"
|
75
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
64
|
none: false
|
77
|
-
requirements:
|
78
|
-
- -
|
79
|
-
- !ruby/object:Gem::Version
|
80
|
-
|
81
|
-
segments:
|
82
|
-
- 0
|
83
|
-
version: "0"
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
84
69
|
requirements: []
|
85
|
-
|
86
70
|
rubyforge_project:
|
87
|
-
rubygems_version: 1.
|
71
|
+
rubygems_version: 1.8.23
|
88
72
|
signing_key:
|
89
73
|
specification_version: 3
|
90
74
|
summary: Adds a pulse URL that pings the DB to a Rails app.
|
91
|
-
test_files:
|
75
|
+
test_files:
|
92
76
|
- spec/pulse_spec.rb
|
93
77
|
- spec/spec.opts
|
94
78
|
- spec/spec_helper.rb
|
79
|
+
has_rdoc: false
|