Class: Metricstore::Updater
- Inherits:
-
Object
- Object
- Metricstore::Updater
- Defined in:
- lib/metricstore/updater.rb
Overview
Abstract class. Not thread-safe.
Sub-classes must implement (protected) methods:
prepare_data(data)
consolidate_data(data1, data2)
handle_update(key, data, ttl, errors)
-> must return a truthy value if and only if the update occurred.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#handle_update_result ⇒ Object
Returns the value of attribute handle_update_result.
Instance Method Summary collapse
-
#backlog ⇒ Object
Approximate length of the queue.
- #healthy? ⇒ Boolean
-
#initialize(opts = {}) ⇒ Updater
constructor
opts: :sleep_interval - sleep cycle length in seconds (default: 0.1).
- #start! ⇒ Object
-
#stop! ⇒ Object
Be sure to call this after tests, when you want to let go of the object.
Constructor Details
#initialize(opts = {}) ⇒ Updater
opts:
:sleep_interval - sleep cycle length in seconds (default: 0.1).
:kvstore - the underlying key-value store.
:max_retry_delay_in_seconds - maximum length of time to wait after an error.
:max_unhandled_errors - maximum number of retries before handling errors. Set this >= max_healthy_errors.
:max_healthy_errors - maximum number of retries before healhty? returns false. Set this <= max_unhandled_errors.
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/metricstore/updater.rb', line 24 def initialize(opts={}) @sleep_interval = (opts[:sleep_interval] || 0.1).to_f @kvstore = required(opts, :kvstore) @max_retry_delay = required(opts, :max_retry_delay_in_seconds).to_f @max_unhandled_errors = required(opts, :max_unhandled_errors).to_i @max_healthy_errors = required(opts, :max_healthy_errors).to_i @timer = nil @running = false @healthy = nil @pending_updates = {} end |
Instance Attribute Details
#handle_update_result ⇒ Object
Returns the value of attribute handle_update_result.
61 62 63 |
# File 'lib/metricstore/updater.rb', line 61 def handle_update_result @handle_update_result end |
Instance Method Details
#backlog ⇒ Object
Approximate length of the queue
57 58 59 |
# File 'lib/metricstore/updater.rb', line 57 def backlog @pending_updates.size end |
#healthy? ⇒ Boolean
52 53 54 |
# File 'lib/metricstore/updater.rb', line 52 def healthy? @healthy != false end |
#start! ⇒ Object
37 38 39 40 41 |
# File 'lib/metricstore/updater.rb', line 37 def start! return if @running @running = true EM.next_tick { process! } end |
#stop! ⇒ Object
Be sure to call this after tests, when you want to let go of the object.
44 45 46 47 48 49 50 |
# File 'lib/metricstore/updater.rb', line 44 def stop! @running = false if timer = @timer EM.cancel_timer(timer) @timer = nil end end |