Class: Heartcheck::Checks::Base
- Inherits:
-
Object
- Object
- Heartcheck::Checks::Base
- Defined in:
- lib/heartcheck/checks/base.rb
Overview
Base check that contains the common functionality for chechs
Instance Attribute Summary collapse
-
#dev ⇒ Boolean
(also: #dev?)
When it is true the check will work just for ‘/dev` route.
-
#functional ⇒ Boolean
(also: #functional?)
When it is true the check will work just for ‘/functional` route.
-
#name ⇒ String
The name for identify the check in the result page.
-
#timeout ⇒ Integer
Time that the check has to execute.
Instance Method Summary collapse
-
#add_service(service) ⇒ void
It is used to add a service that will use when check run.
-
#check ⇒ Hash
run the check and return formated erros.
- #informations ⇒ Object
-
#initialize ⇒ Check
constructor
Create a new instance and set the default values.
-
#on_error(&block) ⇒ void
Seter to add a proc to execute when some check fail.
-
#register_dynamic_services(&block) ⇒ void
It is used to register dynamic services thats need to be evaluate when the checker is running.
-
#services ⇒ Array<Hash>
It is used to add a service that will use when check run.
-
#to_validate {|services, errors| ... } ⇒ void
Seter to add a proc to execute to check.
Constructor Details
#initialize ⇒ Check
Create a new instance and set the default values.
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/heartcheck/checks/base.rb', line 37 def initialize @dynamic_services = nil @error_proc = nil @errors = [] @functional = false @dev = false @name = self.class.name.split('::').last.downcase @services = [] @timeout = 0 @validate_proc = nil end |
Instance Attribute Details
#dev ⇒ Boolean Also known as: dev?
When it is true the check will work just for ‘/dev` route.
you can use it to create some check is not essential/functional for you app.
For example you can execute some performance check.
19 20 21 |
# File 'lib/heartcheck/checks/base.rb', line 19 def dev @dev end |
#functional ⇒ Boolean Also known as: functional?
When it is true the check will work just for ‘/functional` route.
It should be used to add warning messages that need to verify,
but doesn't break your application.
For example when your async process has more than 3 jobs.
11 12 13 |
# File 'lib/heartcheck/checks/base.rb', line 11 def functional @functional end |
#name ⇒ String
The name for identify the check in the result page
25 26 27 |
# File 'lib/heartcheck/checks/base.rb', line 25 def name @name end |
#timeout ⇒ Integer
Time that the check has to execute.
If it is 0 the timeout will be disable
31 32 33 |
# File 'lib/heartcheck/checks/base.rb', line 31 def timeout @timeout end |
Instance Method Details
#add_service(service) ⇒ void
This method returns an undefined value.
It is used to add a service that will use when check run.
96 97 98 |
# File 'lib/heartcheck/checks/base.rb', line 96 def add_service(service) @services << service end |
#check ⇒ Hash
run the check and return formated erros
115 116 117 118 119 120 |
# File 'lib/heartcheck/checks/base.rb', line 115 def check validation { name => { 'status' => (@errors.empty? ? 'ok' : 'error') } }.tap do |response| response[name]['message'] = unless @errors.empty? end end |
#informations ⇒ Object
122 123 124 125 126 |
# File 'lib/heartcheck/checks/base.rb', line 122 def informations info rescue => e { 'error' => e. } end |
#on_error(&block) ⇒ void
This method returns an undefined value.
Seter to add a proc to execute when some check fail.
52 53 54 |
# File 'lib/heartcheck/checks/base.rb', line 52 def on_error(&block) @error_proc = block if block_given? end |
#register_dynamic_services(&block) ⇒ void
This method returns an undefined value.
It is used to register dynamic services thats need to be evaluate when the checker is running.
This proc need to return an Array.
84 85 86 |
# File 'lib/heartcheck/checks/base.rb', line 84 def register_dynamic_services(&block) @dynamic_services = block if block_given? end |
#services ⇒ Array<Hash>
It is used to add a service that will use when check run.
104 105 106 107 108 109 110 |
# File 'lib/heartcheck/checks/base.rb', line 104 def services if @dynamic_services @services + @dynamic_services.call else @services end end |
#to_validate {|services, errors| ... } ⇒ void
This method returns an undefined value.
Seter to add a proc to execute to check.
69 70 71 |
# File 'lib/heartcheck/checks/base.rb', line 69 def to_validate(&block) @validate_proc = block if block_given? end |