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.
-
#doc_url ⇒ String
An url to provide more info about the check.
-
#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.
-
#inspect ⇒ String
Returns a human-readable representation of the check.
-
#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.
-
#uri_info ⇒ Hash
Returns a structure comprised of host, port and schema (protocol) for the check.
Constructor Details
#initialize ⇒ Check
Create a new instance and set the default values.
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/heartcheck/checks/base.rb', line 44 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 |
#doc_url ⇒ String
An url to provide more info about the check.
It is important to provide details about the failure, for example:
- what is the impact
- how to fix it
- how to reproduce the failure
39 40 41 |
# File 'lib/heartcheck/checks/base.rb', line 39 def doc_url @doc_url 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 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.
103 104 105 |
# File 'lib/heartcheck/checks/base.rb', line 103 def add_service(service) @services << service end |
#check ⇒ Hash
run the check and return formated erros
122 123 124 125 126 127 |
# File 'lib/heartcheck/checks/base.rb', line 122 def check validation { name => { 'status' => (@errors.empty? ? 'ok' : 'error') } }.tap do |response| response[name]['message'] = unless @errors.empty? end end |
#informations ⇒ Object
144 145 146 147 148 |
# File 'lib/heartcheck/checks/base.rb', line 144 def informations info rescue => e { 'error' => e. } end |
#inspect ⇒ String
Returns a human-readable representation of the check
132 133 134 |
# File 'lib/heartcheck/checks/base.rb', line 132 def inspect "#<#{self.class.name} name: #{name}, functional: #{functional?}, dev: #{dev?}>" end |
#on_error(&block) ⇒ void
This method returns an undefined value.
Seter to add a proc to execute when some check fail.
59 60 61 |
# File 'lib/heartcheck/checks/base.rb', line 59 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.
91 92 93 |
# File 'lib/heartcheck/checks/base.rb', line 91 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.
111 112 113 114 115 116 117 |
# File 'lib/heartcheck/checks/base.rb', line 111 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.
76 77 78 |
# File 'lib/heartcheck/checks/base.rb', line 76 def to_validate(&block) @validate_proc = block if block_given? end |
#uri_info ⇒ Hash
Returns a structure comprised of host, port and schema (protocol) for the check
140 141 142 |
# File 'lib/heartcheck/checks/base.rb', line 140 def uri_info { error: "#{self.class.name} #url_info not implemented." } end |