Class: Trevosdk::ConfigPoller

Inherits:
Object
  • Object
show all
Defined in:
lib/trevosdk/poller.rb

Overview

Fetches experiment config on an interval and hands parsed snapshots to the client.

Instance Method Summary collapse

Constructor Details

#initialize(config_url:, secret_key:, interval_s:, transport:, on_config:, on_error:) ⇒ ConfigPoller

Returns a new instance of ConfigPoller.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/trevosdk/poller.rb', line 9

def initialize(config_url:, secret_key:, interval_s:, transport:, on_config:, on_error:)
  @config_url = config_url
  @secret_key = secret_key
  @interval_s = interval_s
  @transport = transport
  @on_config = on_config
  @on_error = on_error

  @etag = nil
  @stop_mutex = Mutex.new
  @stop_cv = ConditionVariable.new
  @stopped = false
  @ready_mutex = Mutex.new
  @ready_cv = ConditionVariable.new
  @ready = false
  @worker = nil
end

Instance Method Details

#startObject



27
28
29
30
31
# File 'lib/trevosdk/poller.rb', line 27

def start
  return unless @worker.nil?
  @worker = Thread.new { run }
  @worker.name = "trevosdk-poller"
end

#stopObject



40
41
42
43
44
45
46
47
# File 'lib/trevosdk/poller.rb', line 40

def stop
  @stop_mutex.synchronize do
    @stopped = true
    @stop_cv.signal
  end
  @worker&.join(1)
  @worker = nil
end

#wait_ready(timeout_s = nil) ⇒ Object



33
34
35
36
37
38
# File 'lib/trevosdk/poller.rb', line 33

def wait_ready(timeout_s = nil)
  @ready_mutex.synchronize do
    @ready_cv.wait(@ready_mutex, timeout_s) unless @ready
    @ready
  end
end