Class: Unleash::StreamingClientExecutor
- Inherits:
-
Object
- Object
- Unleash::StreamingClientExecutor
- Defined in:
- lib/unleash/streaming_client_executor.rb
Instance Attribute Summary collapse
-
#event_processor ⇒ Object
Returns the value of attribute event_processor.
-
#event_source ⇒ Object
Returns the value of attribute event_source.
-
#name ⇒ Object
Returns the value of attribute name.
-
#running ⇒ Object
Returns the value of attribute running.
Instance Method Summary collapse
-
#initialize(name, engine) ⇒ StreamingClientExecutor
constructor
A new instance of StreamingClientExecutor.
- #run(&_block) ⇒ Object
- #running? ⇒ Boolean
- #start ⇒ Object
- #stop ⇒ Object (also: #exit)
Constructor Details
#initialize(name, engine) ⇒ StreamingClientExecutor
Returns a new instance of StreamingClientExecutor.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/unleash/streaming_client_executor.rb', line 10 def initialize(name, engine) self.name = name || 'StreamingClientExecutor' self.event_source = nil self.event_processor = Unleash::StreamingEventProcessor.new(engine) self.running = false begin # if bootstrap configuration is available, initialize. Otherwise read backup file if Unleash.configuration.use_bootstrap? bootstrap(engine) else read_backup_file!(engine) end rescue StandardError => e # fall back to reading the backup file Unleash.logger.warn "StreamingClientExecutor was unable to initialize, attempting to read from backup file." Unleash.logger.debug "Exception Caught: #{e}" read_backup_file!(engine) end end |
Instance Attribute Details
#event_processor ⇒ Object
Returns the value of attribute event_processor.
8 9 10 |
# File 'lib/unleash/streaming_client_executor.rb', line 8 def event_processor @event_processor end |
#event_source ⇒ Object
Returns the value of attribute event_source.
8 9 10 |
# File 'lib/unleash/streaming_client_executor.rb', line 8 def event_source @event_source end |
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'lib/unleash/streaming_client_executor.rb', line 8 def name @name end |
#running ⇒ Object
Returns the value of attribute running.
8 9 10 |
# File 'lib/unleash/streaming_client_executor.rb', line 8 def running @running end |
Instance Method Details
#run(&_block) ⇒ Object
31 32 33 |
# File 'lib/unleash/streaming_client_executor.rb', line 31 def run(&_block) start end |
#running? ⇒ Boolean
59 60 61 |
# File 'lib/unleash/streaming_client_executor.rb', line 59 def running? self.running end |
#start ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/unleash/streaming_client_executor.rb', line 35 def start return if self.running || Unleash.configuration.disable_client Unleash.logger.debug "Streaming client #{self.name} starting connection to: #{Unleash.configuration.fetch_toggles_uri}" self.event_source = create_event_source setup_event_handlers self.running = true Unleash.logger.debug "Streaming client #{self.name} connection established" end |
#stop ⇒ Object Also known as: exit
47 48 49 50 51 52 53 54 55 |
# File 'lib/unleash/streaming_client_executor.rb', line 47 def stop return unless self.running Unleash.logger.debug "Streaming client #{self.name} stopping connection" self.running = false self.event_source&.close self.event_source = nil Unleash.logger.debug "Streaming client #{self.name} connection closed" end |