Class: Sidekiq::Throttled::Communicator::Listener

Inherits:
Thread
  • Object
show all
Includes:
ExceptionHandler
Defined in:
lib/sidekiq/throttled/communicator/listener.rb

Overview

Redis subscription listener thread.

Instance Method Summary collapse

Constructor Details

#initialize(channel, callbacks) ⇒ Listener

Starts listener thread.



18
19
20
21
22
23
24
25
# File 'lib/sidekiq/throttled/communicator/listener.rb', line 18

def initialize(channel, callbacks)
  @channel    = channel
  @callbacks  = callbacks
  @terminated = false
  @subscribed = false

  super { listen until @terminated }
end

Instance Method Details

#listening?Boolean

Whenever main loop is still running.



37
38
39
# File 'lib/sidekiq/throttled/communicator/listener.rb', line 37

def listening?
  !@terminated
end

#ready?Boolean

Whenever underlying redis client subscribed to pub/sup channel.



30
31
32
# File 'lib/sidekiq/throttled/communicator/listener.rb', line 30

def ready?
  @subscribed
end

#stopvoid

This method returns an undefined value.

Stops listener.

Raises:

  • (Sidekiq::Shutdown)


44
45
46
47
48
49
50
# File 'lib/sidekiq/throttled/communicator/listener.rb', line 44

def stop
  # Raising exception while client is in subscription mode makes
  # redis close connection and thus causing ConnectionPool reopen
  # it (normal mode). Otherwise subscription mode client will be
  # pushed back to ConnectionPool causing problems.
  raise Sidekiq::Shutdown
end