Class: ServiceJynx::Jynx
- Inherits:
-
Object
- Object
- ServiceJynx::Jynx
- Defined in:
- lib/service_jynx.rb
Instance Attribute Summary collapse
-
#alive ⇒ Object
Returns the value of attribute alive.
-
#down_at ⇒ Object
Returns the value of attribute down_at.
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#grace_period ⇒ Object
Returns the value of attribute grace_period.
-
#max_errors ⇒ Object
Returns the value of attribute max_errors.
-
#name ⇒ Object
Returns the value of attribute name.
-
#time_window_in_seconds ⇒ Object
Returns the value of attribute time_window_in_seconds.
Instance Method Summary collapse
- #alive? ⇒ Boolean
-
#clean_aged(time_now) ⇒ Object
clean up errors that are older than time_window_in_secons.
- #down!(reason) ⇒ Object
-
#initialize(name, options) ⇒ Jynx
constructor
A new instance of Jynx.
- #up! ⇒ Object
Constructor Details
#initialize(name, options) ⇒ Jynx
Returns a new instance of Jynx.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/service_jynx.rb', line 47 def initialize(name, ) @name = name @down_at = 0 @alive = true @errors = [] opts = { time_window_in_seconds: 10, max_errors: 40, grace_period: 360 }.merge!() @time_window_in_seconds = opts[:time_window_in_seconds] @max_errors = opts[:max_errors] @grace_period = opts[:grace_period] end |
Instance Attribute Details
#alive ⇒ Object
Returns the value of attribute alive.
46 47 48 |
# File 'lib/service_jynx.rb', line 46 def alive @alive end |
#down_at ⇒ Object
Returns the value of attribute down_at.
46 47 48 |
# File 'lib/service_jynx.rb', line 46 def down_at @down_at end |
#errors ⇒ Object
Returns the value of attribute errors.
46 47 48 |
# File 'lib/service_jynx.rb', line 46 def errors @errors end |
#grace_period ⇒ Object
Returns the value of attribute grace_period.
46 47 48 |
# File 'lib/service_jynx.rb', line 46 def grace_period @grace_period end |
#max_errors ⇒ Object
Returns the value of attribute max_errors.
46 47 48 |
# File 'lib/service_jynx.rb', line 46 def max_errors @max_errors end |
#name ⇒ Object
Returns the value of attribute name.
46 47 48 |
# File 'lib/service_jynx.rb', line 46 def name @name end |
#time_window_in_seconds ⇒ Object
Returns the value of attribute time_window_in_seconds.
46 47 48 |
# File 'lib/service_jynx.rb', line 46 def time_window_in_seconds @time_window_in_seconds end |
Instance Method Details
#alive? ⇒ Boolean
80 81 82 83 84 85 |
# File 'lib/service_jynx.rb', line 80 def alive? return true if @alive near_past = Time.now.to_i - @grace_period up! if (@down_at < near_past) and return true false end |
#clean_aged(time_now) ⇒ Object
clean up errors that are older than time_window_in_secons
63 64 65 66 |
# File 'lib/service_jynx.rb', line 63 def clean_aged(time_now) near_past = time_now - @time_window_in_seconds @errors = @errors.reverse.select{|time_stamp| time_stamp > near_past }.reverse.to_a end |
#down!(reason) ⇒ Object
68 69 70 71 72 |
# File 'lib/service_jynx.rb', line 68 def down!(reason) @alive = false @down_at = Time.now.to_i LoggerJynx.logger.error "Shutting down [#{@name}] #{reason} at #{@down_at}." end |
#up! ⇒ Object
74 75 76 77 78 |
# File 'lib/service_jynx.rb', line 74 def up! LoggerJynx.logger.error "Upping [#{@name}]." @alive = true @down_at = 0 end |