Class: Flipper::Adapters::Sync::IntervalSynchronizer

Inherits:
Object
  • Object
show all
Defined in:
lib/flipper/adapters/sync/interval_synchronizer.rb

Overview

Internal: Wraps a Synchronizer instance and only invokes it every N seconds.

Constant Summary collapse

DEFAULT_INTERVAL =

Private: Number of seconds between syncs (default: 10).

10

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(synchronizer, interval: nil) ⇒ IntervalSynchronizer

Public: Initializes a new interval synchronizer.

synchronizer - The Synchronizer to call when the interval has passed. interval - The Integer number of seconds between invocations of

the wrapped synchronizer.


19
20
21
22
23
24
25
# File 'lib/flipper/adapters/sync/interval_synchronizer.rb', line 19

def initialize(synchronizer, interval: nil)
  @synchronizer = synchronizer
  @interval = interval || DEFAULT_INTERVAL
  # TODO: add jitter to this so all processes booting at the same time
  # don't phone home at the same time.
  @last_sync_at = 0
end

Instance Attribute Details

#intervalObject (readonly)

Public: The Float or Integer number of seconds between invocations of the wrapped synchronizer.



12
13
14
# File 'lib/flipper/adapters/sync/interval_synchronizer.rb', line 12

def interval
  @interval
end

Instance Method Details

#callObject



27
28
29
30
31
32
33
34
# File 'lib/flipper/adapters/sync/interval_synchronizer.rb', line 27

def call
  return unless time_to_sync?

  @last_sync_at = now
  @synchronizer.call

  nil
end