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 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
- map '/ping' do
9
- run Pingable::Handler
10
- end
11
- run MyApp
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
- Pingable.add_check lambda {
16
- unless check_something
17
- "Oh noes, something failed"
18
- end
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
- class TwitterCheck
36
- def initialize(url)
37
- @url = url
38
- end
39
+ ```ruby
40
+ class TwitterCheck
41
+ def initialize(url)
42
+ @url = url
43
+ end
39
44
 
40
- def call
41
- # ... check the URL ...
42
- end
43
- end
45
+ def call
46
+ # ... check the URL ...
47
+ end
48
+ end
44
49
 
45
- Pingable.add_check TwitterCheck.new(:url => "http://twitter.com/")
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
- map '/ping' do
53
- use Pingable::Handler, 'my fancy app'
54
- end
55
- run MyApp
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. To install these, add the following:
77
+ Pingable comes with a set of checks that are commonly needed for web applications:
70
78
 
71
- Pingable.common_checks!
79
+ * `Pingable.active_record_checks!`: Checks ActiveRecord.
80
+ * `Pingable.rails_cache_checks!`: Checks Rails cache.
72
81
 
73
- These include:
82
+ To install all common checks based on available dependencies:
74
83
 
75
- * A check to verify ActiveRecord's current connection.
76
- * A check to check the ability for Rails' cache to read and write values.
84
+ ```ruby
85
+ Pingable.common_checks!
86
+ ```
77
87
 
78
- Common checks for are only installed for dependencies that are discovered automatically. For example, if ActiveRecord has not been `require`d, then the ActiveRecord check is not included.
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
- add_active_record!
10
- add_rails_cache!
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
- private
16
-
17
- def add_active_record!
18
- if defined?(ActiveRecord)
19
- require 'timeout'
20
- add_check lambda {
21
- begin
22
- timeout(10) do
23
- ActiveRecord::Base.verify_active_connections!
24
- end
25
- ActiveRecord::Base.connection.execute('select 1')
26
- nil
27
- rescue Timeout::Error
28
- "ActiveRecord: Timed out"
29
- rescue Exception => e
30
- if e.class.name == e.message
31
- "ActiveRecord: #{e}"
32
- else
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
- end
39
+ }
40
+ end
39
41
 
40
- def add_rails_cache!
41
- if defined?(Rails) and Rails.respond_to?(:cache)
42
- add_check lambda {
43
- begin
44
- Rails.cache.read('ping_check')
45
- Rails.cache.write('ping_check', 'ok')
46
- nil
47
- rescue Exception => e
48
- "Rails cache: #{e.class}: #{e.message}"
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
- end
52
+ }
53
+ end
53
54
 
54
55
  end
55
56
 
@@ -1,3 +1,3 @@
1
1
  module Pingable
2
- VERSION = '0.0.8'
2
+ VERSION = '0.0.9'
3
3
  end
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: 15
4
+ hash: 13
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 8
10
- version: 0.0.8
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-01-31 00:00:00 Z
18
+ date: 2012-02-07 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rspec