okcomputer 0.1.3 → 0.2.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.markdown CHANGED
@@ -45,25 +45,26 @@ Register additional checks in an initializer, like do:
45
45
 
46
46
  ```ruby
47
47
  # config/initializers/okcomputer.rb
48
- OKComputer::Registry.register "resque_down", OKComputer::ResqueDownCheck.new("critical", 100)
49
- OKComputer::Registry.register "resque_backed_up", OKComputer::ResqueBackedUpCheck.new
48
+ OKComputer::Registry.register "resque_down", OKComputer::ResqueDownCheck.new
49
+ OKComputer::Registry.register "resque_backed_up", OKComputer::ResqueBackedUpCheck.new("critical", 100)
50
50
  ```
51
51
 
52
52
  ### Registering Custom Checks
53
53
 
54
54
  The simplest way to register a check unique to your application is to subclass
55
- OKComputer::Check and implement your own `#call` method, which returns the
56
- output string, and calls `mark_failure` if anything is wrong.
55
+ OKComputer::Check and implement your own `#check` method, which sets the
56
+ display message with `mark_message`, and calls `mark_failure` if anything is
57
+ wrong.
57
58
 
58
59
  ```ruby
59
60
  # config/initializers/okcomputer.rb
60
61
  class MyCustomCheck < OKComputer::Check
61
- def call
62
+ def check
62
63
  if rand(10).even?
63
- "Even is great!"
64
+ mark_message "Even is great!"
64
65
  else
65
66
  mark_failure
66
- "We don't like odd numbers"
67
+ mark_message "We don't like odd numbers"
67
68
  end
68
69
  end
69
70
  end
@@ -71,6 +72,14 @@ end
71
72
  OKComputer::Registry.register "check_for_odds", MyCustomCheck.new
72
73
  ```
73
74
 
75
+ #### Deprecation of Check#call
76
+
77
+ Versions before 0.2.0 implemented a "#call" method which returned the message.
78
+ This has been deprecated and will be removed in a future version. Please
79
+ define a #check method which calls `mark_failure` and `mark_message` as
80
+ appropriate. In the meantime, OKComputer displays a warning and uses the result
81
+ of the #call method as the message.
82
+
74
83
  ## Performing Checks
75
84
 
76
85
  * Perform a simple up check: http://example.com/okcomputer
@@ -4,12 +4,14 @@ class OkComputerController < ActionController::Base
4
4
 
5
5
  def index
6
6
  checks = OKComputer::Registry.all
7
+ checks.run
7
8
 
8
9
  respond_with checks, status: status_code(checks)
9
10
  end
10
11
 
11
12
  def show
12
13
  check = OKComputer::Registry.fetch(params[:check])
14
+ check.run
13
15
 
14
16
  respond_with check, status: status_code(check)
15
17
  end
@@ -1,11 +1,11 @@
1
1
  module OKComputer
2
2
  class ActiveRecordCheck < Check
3
3
  # Public: Return the schema version of the database
4
- def call
5
- "Schema version: #{schema_version}"
4
+ def check
5
+ mark_message "Schema version: #{schema_version}"
6
6
  rescue ConnectionFailed => e
7
7
  mark_failure
8
- "Failed to connect: '#{e}'"
8
+ mark_message "Failed to connect: '#{e}'"
9
9
  end
10
10
 
11
11
  # Public: The scema version of the app's database
@@ -1,8 +1,8 @@
1
1
  module OKComputer
2
2
  class DefaultCheck < Check
3
3
  # Public: Check that Rails can render anything at all
4
- def call
5
- "OKComputer Site Check Passed"
4
+ def check
5
+ mark_message "OKComputer Site Check Passed"
6
6
  end
7
7
  end
8
8
  end
@@ -1,11 +1,11 @@
1
1
  module OKComputer
2
2
  class MongoidCheck < Check
3
3
  # Public: Return the status of the mongodb
4
- def call
5
- "Successfully connected to mongodb #{mongodb_name}"
4
+ def check
5
+ mark_message "Successfully connected to mongodb #{mongodb_name}"
6
6
  rescue ConnectionFailed => e
7
7
  mark_failure
8
- "Failed to connect: '#{e}'"
8
+ mark_message "Failed to connect: '#{e}'"
9
9
  end
10
10
 
11
11
  # Public: The stats for the app's mongodb
@@ -14,12 +14,12 @@ module OKComputer
14
14
  end
15
15
 
16
16
  # Public: Check whether the given queue is backed up
17
- def call
17
+ def check
18
18
  if count <= threshold
19
- "Resque queue '#{queue}' at reasonable level (#{count})"
19
+ mark_message "Resque queue '#{queue}' at reasonable level (#{count})"
20
20
  else
21
21
  mark_failure
22
- "Resque queue '#{queue}' backed up! (#{count})"
22
+ mark_message "Resque queue '#{queue}' backed up! (#{count})"
23
23
  end
24
24
  end
25
25
 
@@ -1,12 +1,12 @@
1
1
  module OKComputer
2
2
  class ResqueDownCheck < Check
3
3
  # Public: Check whether Resque workers are working
4
- def call
4
+ def check
5
5
  if queued? and not working?
6
6
  mark_failure
7
- "Resque is DOWN. No workers are working the queue."
7
+ mark_message "Resque is DOWN. No workers are working the queue."
8
8
  else
9
- "Resque is working"
9
+ mark_message "Resque is working"
10
10
  end
11
11
  end
12
12
 
@@ -1,23 +1,40 @@
1
1
  module OKComputer
2
2
  class Check
3
+ CALL_DEPRECATION_MESSAGE = "Deprecation warning: Please define #check rather than defining #call"
4
+
3
5
  # to be set by Registry upon registration
4
6
  attr_accessor :name
5
7
  # nil by default, only set to true if the check deems itself failed
6
8
  attr_accessor :failure_occurred
9
+ # nil by default, set by #check to control the output
10
+ attr_accessor :message
11
+
12
+ # Public: Run the check
13
+ def run
14
+ clear
15
+ check
16
+ end
7
17
 
8
- # Public: Perform the appropriate check
18
+ # Private: Perform the appropriate check
9
19
  #
10
- # Your subclass of Check must define its own #call method. This method
20
+ # Your subclass of Check must define its own #check method. This method
11
21
  # must return the string to render when performing the check.
12
- def call
13
- raise(CallNotDefined, "Your subclass must define its own #call.")
22
+ def check
23
+ if respond_to? :call
24
+ warn CALL_DEPRECATION_MESSAGE
25
+ # The old #call methods returned the message, so use that to set the message output
26
+ mark_message call
27
+ else
28
+ raise(CheckNotDefined, "Your subclass must define its own #check.")
29
+ end
14
30
  end
31
+ private :check
15
32
 
16
33
  # Public: The text output of performing the check
17
34
  #
18
35
  # Returns a String
19
36
  def to_text
20
- "#{name}: #{call}"
37
+ "#{name}: #{message}"
21
38
  end
22
39
 
23
40
  # Public: The JSON output of performing the check
@@ -26,7 +43,7 @@ module OKComputer
26
43
  def to_json(*args)
27
44
  # NOTE swallowing the arguments that Rails passes by default since we don't care. This may prove to be a bad idea
28
45
  # Rails passes stuff like this: {:prefixes=>["ok_computer", "application"], :template=>"show", :layout=>#<Proc>}]
29
- {name => call}.to_json
46
+ {name => message}.to_json
30
47
  end
31
48
 
32
49
  # Public: Whether the check passed
@@ -41,6 +58,19 @@ module OKComputer
41
58
  self.failure_occurred = true
42
59
  end
43
60
 
44
- CallNotDefined = Class.new(StandardError)
61
+ # Public: Capture the desired message to display
62
+ #
63
+ # message - Text of the message to display for this check
64
+ def mark_message(message)
65
+ self.message = message
66
+ end
67
+
68
+ # Public: Clear any prior failures
69
+ def clear
70
+ self.failure_occurred = false
71
+ self.message = nil
72
+ end
73
+
74
+ CheckNotDefined = Class.new(StandardError)
45
75
  end
46
76
  end
@@ -10,6 +10,11 @@ module OKComputer
10
10
  self.registry = registry
11
11
  end
12
12
 
13
+ # Public: Run the registry's checks
14
+ def run
15
+ checks.each(&:run)
16
+ end
17
+
13
18
  # Public: The list of checks in the collection
14
19
  #
15
20
  # Returns an Array of the registry's values
@@ -1,3 +1,3 @@
1
1
  module OKComputer
2
- VERSION = "0.1.3"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -2,14 +2,14 @@
2
2
  name: okcomputer
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.3
5
+ version: 0.2.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Patrick Byrne
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-02 00:00:00.000000000 Z
12
+ date: 2013-01-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  version_requirements: !ruby/object:Gem::Requirement
@@ -99,7 +99,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
99
99
  version: '0'
100
100
  segments:
101
101
  - 0
102
- hash: -847942118796970126
102
+ hash: -1241122917546608114
103
103
  none: false
104
104
  required_rubygems_version: !ruby/object:Gem::Requirement
105
105
  requirements:
@@ -108,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
108
  version: '0'
109
109
  segments:
110
110
  - 0
111
- hash: -847942118796970126
111
+ hash: -1241122917546608114
112
112
  none: false
113
113
  requirements: []
114
114
  rubyforge_project: