Class: SplitIoClient::Engine::PushManager

Inherits:
Object
  • Object
show all
Defined in:
lib/splitclient-rb/engine/push_manager.rb

Instance Method Summary collapse

Constructor Details

#initialize(config, sse_handler, api_key, telemetry_runtime_producer) ⇒ PushManager

Returns a new instance of PushManager.



6
7
8
9
10
11
12
13
# File 'lib/splitclient-rb/engine/push_manager.rb', line 6

def initialize(config, sse_handler, api_key, telemetry_runtime_producer)
  @config = config
  @sse_handler = sse_handler
  @auth_api_client = AuthApiClient.new(@config, telemetry_runtime_producer)
  @api_key = api_key
  @back_off = Engine::BackOff.new(@config.auth_retry_back_off_base, 1)
  @telemetry_runtime_producer = telemetry_runtime_producer
end

Instance Method Details

#start_sseObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/splitclient-rb/engine/push_manager.rb', line 15

def start_sse
  response = @auth_api_client.authenticate(@api_key)
  @config.logger.debug("Auth service response push_enabled: #{response[:push_enabled]}") if @config.debug_enabled

  if response[:push_enabled] && @sse_handler.start(response[:token], response[:channels])
    schedule_next_token_refresh(response[:exp])
    @back_off.reset
    record_telemetry(response[:exp])

    return true
  end

  stop_sse
  schedule_next_token_refresh(@back_off.interval) if response[:retry]
  false
rescue StandardError => e
  @config.logger.error("start_sse: #{e.inspect}")
end

#stop_sseObject



34
35
36
37
38
39
# File 'lib/splitclient-rb/engine/push_manager.rb', line 34

def stop_sse
  @sse_handler.stop
  SplitIoClient::Helpers::ThreadHelper.stop(:schedule_next_token_refresh, @config)
rescue StandardError => e
  @config.logger.error(e.inspect)
end