Class: GoFlippy::Poller
- Inherits:
-
Object
- Object
- GoFlippy::Poller
- Includes:
- Logger
- Defined in:
- lib/goflippy-ruby/poller.rb
Constant Summary
Constants included from Logger
Instance Method Summary collapse
-
#initialize(polling_interval, http_client, store) ⇒ Poller
constructor
A new instance of Poller.
- #start ⇒ Object
Methods included from Logger
debug, error, fatal, info, logger, logger=, unknown, warn
Constructor Details
#initialize(polling_interval, http_client, store) ⇒ Poller
Returns a new instance of Poller.
5 6 7 8 9 |
# File 'lib/goflippy-ruby/poller.rb', line 5 def initialize(polling_interval, http_client, store) @polling_interval = polling_interval @http_client = http_client @store = store end |
Instance Method Details
#start ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/goflippy-ruby/poller.rb', line 11 def start Logger.debug('Start polling worker process') Worker.create(@polling_interval) do keys = [] @http_client.get('/features')&.each do |feature| uids = @store.find(feature[:key]) uids.each do |uid| enabled = @http_client.get("/users/#{uid}/features/#{key}")&.dig(:enabled) @store.put(feature[:key], { uid: uid.to_sym, enabled: enabled }) end keys << feature[:key] end Logger.info("Polling finished. #{keys.inspect}") @store.refresh!(keys) end end |