Class: Flipper::Adapters::Sync::IntervalSynchronizer
- Inherits:
-
Object
- Object
- Flipper::Adapters::Sync::IntervalSynchronizer
- 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
-
#interval ⇒ Object
readonly
Public: The Float or Integer number of seconds between invocations of the wrapped synchronizer.
Class Method Summary collapse
-
.now_ms ⇒ Object
Private.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(synchronizer, interval: nil) ⇒ IntervalSynchronizer
constructor
Public: Initializes a new interval synchronizer.
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 milliseconds between invocations of
the wrapped synchronizer.
24 25 26 27 28 29 30 |
# File 'lib/flipper/adapters/sync/interval_synchronizer.rb', line 24 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
#interval ⇒ Object (readonly)
Public: The Float or Integer number of seconds between invocations of the wrapped synchronizer.
17 18 19 |
# File 'lib/flipper/adapters/sync/interval_synchronizer.rb', line 17 def interval @interval end |
Class Method Details
.now_ms ⇒ Object
Private
11 12 13 |
# File 'lib/flipper/adapters/sync/interval_synchronizer.rb', line 11 def self.now_ms Process.clock_gettime(Process::CLOCK_MONOTONIC, :millisecond) end |
Instance Method Details
#call ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/flipper/adapters/sync/interval_synchronizer.rb', line 32 def call return unless time_to_sync? @last_sync_at = now_ms @synchronizer.call nil end |