Class: Kameleoon::RealTime::RealTimeConfigurationService

Inherits:
Object
  • Object
show all
Defined in:
lib/kameleoon/real_time/real_time_configuration_service.rb

Overview

RealTimeConfigurationService is used for fetching updates of configuration (experiments and feature flags) in real time.

Instance Method Summary collapse

Constructor Details

#initialize(url, update_handler, log_func, sse_request_source = nil) ⇒ RealTimeConfigurationService

Parametrized initializer.

is synchronously called for gotten RealTimeEvent objects.

Parameters:

  • url (String)
  • update_handler (Callable[Kameleoon::RealTime::RealTimeEvent] | NilClass)

    Handler which

  • log_func (Callable[String] | NilClass)

    Callable object which synchronously called to log.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/kameleoon/real_time/real_time_configuration_service.rb', line 25

def initialize(url, update_handler, log_func, sse_request_source = nil)
  @url = url
  @update_handler = update_handler
  @need_close = false
  @headers = {
    'Accept': 'text/event-stream',
    'Cache-Control': 'no-cache',
    'Connection': 'Keep-Alive'
  }
  @log_func = log_func
  @sse_request_source = sse_request_source
  @sse_thread = nil
  @sse_client = nil
  create_sse_client
end

Instance Method Details

#closeObject

Closes the connection to the server.



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/kameleoon/real_time/real_time_configuration_service.rb', line 43

def close
  return if @need_close

  @log_func&.call('Real-time configuration service is shutting down')
  @need_close = true
  return if @sse_thread.nil?

  @sse_thread.kill
  @sse_thread = nil
  @sse_client.call_close_handler
end