Class: SplitIoClient::SSE::Workers::SplitsWorker
- Inherits:
-
Object
- Object
- SplitIoClient::SSE::Workers::SplitsWorker
- Defined in:
- lib/splitclient-rb/sse/workers/splits_worker.rb
Instance Method Summary collapse
- #add_to_queue(change_number) ⇒ Object
-
#initialize(synchronizer, config, splits_repository) ⇒ SplitsWorker
constructor
A new instance of SplitsWorker.
- #kill_split(change_number, split_name, default_treatment) ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(synchronizer, config, splits_repository) ⇒ SplitsWorker
Returns a new instance of SplitsWorker.
9 10 11 12 13 14 15 |
# File 'lib/splitclient-rb/sse/workers/splits_worker.rb', line 9 def initialize(synchronizer, config, splits_repository) @synchronizer = synchronizer @config = config @splits_repository = splits_repository @queue = Queue.new @running = Concurrent::AtomicBoolean.new(false) end |
Instance Method Details
#add_to_queue(change_number) ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/splitclient-rb/sse/workers/splits_worker.rb', line 37 def add_to_queue(change_number) unless @running.value @config.logger.debug('splits worker not running.') return end @config.logger.debug("SplitsWorker add to queue #{change_number}") @queue.push(change_number) end |
#kill_split(change_number, split_name, default_treatment) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/splitclient-rb/sse/workers/splits_worker.rb', line 47 def kill_split(change_number, split_name, default_treatment) unless @running.value @config.logger.debug('splits worker not running.') return end return if @splits_repository.get_change_number.to_i > change_number @config.logger.debug("SplitsWorker kill #{split_name}, #{change_number}") @splits_repository.kill(change_number, split_name, default_treatment) add_to_queue(change_number) end |
#start ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/splitclient-rb/sse/workers/splits_worker.rb', line 17 def start if @running.value @config.logger.debug('splits worker already running.') return end @running.make_true perform_thread end |
#stop ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/splitclient-rb/sse/workers/splits_worker.rb', line 27 def stop unless @running.value @config.logger.debug('splits worker not running.') return end @running.make_false SplitIoClient::Helpers::ThreadHelper.stop(:split_update_worker, @config) end |