Class: GoFlippy::Poller

Inherits:
Object
  • Object
show all
Includes:
Logger
Defined in:
lib/goflippy-ruby/poller.rb

Constant Summary

Constants included from Logger

Logger::MESSAGE_PREFIX

Instance Method Summary collapse

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

#startObject



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