Module: StatusLib
- Defined in:
- lib/status_lib.rb,
lib/status_lib/version.rb
Defined Under Namespace
Classes: ApiDownError, Cache, Config, NullStatusApi, ServiceDownError, StatusApi, StatusInfo
Constant Summary collapse
- VERSION =
"0.0.2"
Class Attribute Summary collapse
-
.server ⇒ Object
readonly
Returns the value of attribute server.
Class Method Summary collapse
-
.config ⇒ Object
Read configuration settings.
-
.configure(settings) ⇒ Object
Configure the gem.
-
.switch(name, status, options = {}) ⇒ Object
Sets the status of a service to up or down.
-
.up?(name) ⇒ Boolean
Checks whether a particular service is up or down.
-
.with_circuit_breaker(name, options = {}) ⇒ Object
Helper method for guarding a block of code with a curcuit breaker.
Class Attribute Details
.server ⇒ Object (readonly)
Returns the value of attribute server.
23 24 25 |
# File 'lib/status_lib.rb', line 23 def server @server end |
Class Method Details
.config ⇒ Object
Read configuration settings
The values that are set to #configure are available here.
92 93 94 |
# File 'lib/status_lib.rb', line 92 def config @config ||= Config.new end |
.configure(settings) ⇒ Object
Configure the gem
Params:
+settings+:: the configuration settings. A hash that may contain:
+:server+:: the URL of the status page service
+:cache_time+:: time to cache status reponses from the API
+:api_call_timeout+:: maximum time to wait for a call to status API
+:down_duration+:: default time to switch a service down for
+:block_timeout+:: default time that a `with_circuit_breaker` can take
84 85 86 |
# File 'lib/status_lib.rb', line 84 def configure(settings) config.update(settings) end |
.switch(name, status, options = {}) ⇒ Object
Sets the status of a service to up or down
Params:
+name+:: the name of the service to update
+status+:: the desired status; either :up or :down
+options+:: additional options. can contain:
+:for+:: the time to keep the service down, in seconds
42 43 44 |
# File 'lib/status_lib.rb', line 42 def switch(name, status, ={}) status_info.switch(name, status, ) end |
.up?(name) ⇒ Boolean
Checks whether a particular service is up or down.
Params:
+name+:: the name of the service to check
30 31 32 |
# File 'lib/status_lib.rb', line 30 def up?(name) status_info.up?(name) end |
.with_circuit_breaker(name, options = {}) ⇒ Object
Helper method for guarding a block of code with a curcuit breaker.
If the code in the block raises an exception or exceeds its timeout, then the associated service status will be set to down for the specified interval, and a StatusLib::ServiceDownError exception will be raised.
If the service is already makred down then the block won’t be evaluated at all, and StatusLib::ServiceDownError will be raised immediately.
+name+:: the name of the service to update
+options+:: additional options. can contain:
+:timeout+:: upper limit on how long the block can take to run
+:down_for+:: the time to keep the service down, in seconds
60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/status_lib.rb', line 60 def with_circuit_breaker(name, ={}) raise ServiceDownError unless up?(name) Timeout::timeout( determine_timeout() ) do yield end rescue Timeout::Error => e handle_exception(e, name, ) raise e rescue => e handle_exception(e, name, ) raise ServiceDownError.new(e) end |