pingable 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +38 -28
- data/lib/pingable/common_checks.rb +39 -38
- data/lib/pingable/version.rb +1 -1
- metadata +4 -4
data/README.md
CHANGED
@@ -5,18 +5,22 @@ Pingable is a simple framework to implement a 'ping' URL in Rack-based web appli
|
|
5
5
|
|
6
6
|
For example, a Rails or Sinatra app's `config.ru` may look like this (Rack 1.4.0 and later):
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
```ruby
|
9
|
+
map '/ping' do
|
10
|
+
run Pingable::Handler
|
11
|
+
end
|
12
|
+
run MyApp
|
13
|
+
```
|
12
14
|
|
13
15
|
Now you can add checks in a modular fashion:
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
```ruby
|
18
|
+
Pingable.add_check lambda {
|
19
|
+
unless check_something
|
20
|
+
"Oh noes, something failed"
|
21
|
+
end
|
22
|
+
}
|
23
|
+
```
|
20
24
|
|
21
25
|
Checks
|
22
26
|
------
|
@@ -32,27 +36,31 @@ A check is simply an object which:
|
|
32
36
|
|
33
37
|
Something a bit more complex:
|
34
38
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
+
```ruby
|
40
|
+
class TwitterCheck
|
41
|
+
def initialize(url)
|
42
|
+
@url = url
|
43
|
+
end
|
39
44
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
45
|
+
def call
|
46
|
+
# ... check the URL ...
|
47
|
+
end
|
48
|
+
end
|
44
49
|
|
45
|
-
|
50
|
+
Pingable.add_check TwitterCheck.new(:url => "http://twitter.com/")
|
51
|
+
```
|
46
52
|
|
47
53
|
Configuration
|
48
54
|
-------------
|
49
55
|
|
50
56
|
To set the name that a successful ping check will return, provide a name in the rackup file:
|
51
57
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
58
|
+
```ruby
|
59
|
+
map '/ping' do
|
60
|
+
use Pingable::Handler.new('my fancy app')
|
61
|
+
end
|
62
|
+
run MyApp
|
63
|
+
```
|
56
64
|
|
57
65
|
Ping check
|
58
66
|
----------
|
@@ -66,16 +74,18 @@ On success, a `200 OK` is returned, with either the application's name as the bo
|
|
66
74
|
Common checks
|
67
75
|
-------------
|
68
76
|
|
69
|
-
Pingable comes with a set of checks that are commonly needed for web applications
|
77
|
+
Pingable comes with a set of checks that are commonly needed for web applications:
|
70
78
|
|
71
|
-
|
79
|
+
* `Pingable.active_record_checks!`: Checks ActiveRecord.
|
80
|
+
* `Pingable.rails_cache_checks!`: Checks Rails cache.
|
72
81
|
|
73
|
-
|
82
|
+
To install all common checks based on available dependencies:
|
74
83
|
|
75
|
-
|
76
|
-
|
84
|
+
```ruby
|
85
|
+
Pingable.common_checks!
|
86
|
+
```
|
77
87
|
|
78
|
-
|
88
|
+
For example, if ActiveRecord has not been `require`d, then the ActiveRecord check is not included.
|
79
89
|
|
80
90
|
License
|
81
91
|
-------
|
@@ -3,53 +3,54 @@ module Pingable
|
|
3
3
|
class << self
|
4
4
|
@@common_checks_added ||= false
|
5
5
|
|
6
|
-
# Add checks for standard gems such as Active Record
|
6
|
+
# Add checks for standard gems such as Active Record, based on
|
7
|
+
# what is currently available.
|
7
8
|
def common_checks!
|
8
9
|
unless @@common_checks_added
|
9
|
-
|
10
|
-
|
10
|
+
if defined?(ActiveRecord)
|
11
|
+
active_record_checks!
|
12
|
+
end
|
13
|
+
if defined?(Rails) and Rails.respond_to?(:cache)
|
14
|
+
rails_cache_checks!
|
15
|
+
end
|
11
16
|
@@common_checks_added = true
|
12
17
|
end
|
13
18
|
end
|
14
19
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
"ActiveRecord: #{e.class}: #{e.message}"
|
34
|
-
end
|
35
|
-
end
|
36
|
-
}
|
20
|
+
# Add checks for ActiveRecord.
|
21
|
+
def active_record_checks!
|
22
|
+
require 'timeout'
|
23
|
+
add_check lambda {
|
24
|
+
begin
|
25
|
+
timeout(10) do
|
26
|
+
ActiveRecord::Base.verify_active_connections!
|
27
|
+
end
|
28
|
+
ActiveRecord::Base.connection.execute('select 1')
|
29
|
+
nil
|
30
|
+
rescue Timeout::Error
|
31
|
+
"ActiveRecord: Timed out"
|
32
|
+
rescue Exception => e
|
33
|
+
if e.class.name == e.message
|
34
|
+
"ActiveRecord: #{e}"
|
35
|
+
else
|
36
|
+
"ActiveRecord: #{e.class}: #{e.message}"
|
37
|
+
end
|
37
38
|
end
|
38
|
-
|
39
|
+
}
|
40
|
+
end
|
39
41
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
end
|
50
|
-
}
|
42
|
+
# Add Rails cache checks.
|
43
|
+
def rails_cache_checks!
|
44
|
+
add_check lambda {
|
45
|
+
begin
|
46
|
+
Rails.cache.read('ping_check')
|
47
|
+
Rails.cache.write('ping_check', 'ok')
|
48
|
+
nil
|
49
|
+
rescue Exception => e
|
50
|
+
"Rails cache: #{e.class}: #{e.message}"
|
51
51
|
end
|
52
|
-
|
52
|
+
}
|
53
|
+
end
|
53
54
|
|
54
55
|
end
|
55
56
|
|
data/lib/pingable/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pingable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 13
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 9
|
10
|
+
version: 0.0.9
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Alexander Staubo
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-
|
18
|
+
date: 2012-02-07 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rspec
|