class Resqued::ListenerPool
Public Class Methods
Public: Initialize a new pool, and store state in the given master’s state.
# File lib/resqued/listener_pool.rb, line 9 def initialize(master_state) @master_state = master_state @listener_proxies = {} # If this master is replacing an old one, there will be listeners in the state already. @master_state.listener_states.each do |pid, ls| @listener_proxies[pid] = ListenerProxy.new(ls) end end
Public Instance Methods
Public: Don’t consider the current listener to be current anymore.
# File lib/resqued/listener_pool.rb, line 66 def clear_current! @master_state.current_listener_pid = nil end
Public: Forget which listener was the last good one.
# File lib/resqued/listener_pool.rb, line 87 def clear_last_good! @master_state.last_good_listener_pid = nil end
Public: The current ListenerProxy
, if available.
# File lib/resqued/listener_pool.rb, line 56 def current @listener_proxies[current_pid] end
Public: The pid of the current listener, if available.
# File lib/resqued/listener_pool.rb, line 61 def current_pid @master_state.current_listener_pid end
Public: Change the current listener into the last good listener.
# File lib/resqued/listener_pool.rb, line 71 def cycle_current @master_state.last_good_listener_pid = @master_state.current_listener_pid @master_state.current_listener_pid = nil end
Public: Remove the given pid from the set of known listeners, and return its ListenerProxy
.
# File lib/resqued/listener_pool.rb, line 50 def delete(pid) @master_state.listener_states.delete(pid) return @listener_proxies.delete(pid) end
Public: Iterate through all active ListenerProxy
instances.
# File lib/resqued/listener_pool.rb, line 19 def each(&block) @listener_proxies.values.each(&block) end
Public: Are the listeners all gone?
# File lib/resqued/listener_pool.rb, line 29 def empty? @listener_proxies.empty? end
Public: The last good (previous current) ListenerProxy
, if available.
# File lib/resqued/listener_pool.rb, line 77 def last_good @listener_proxies[last_good_pid] end
Public: The pid of the last good listener, if available.
# File lib/resqued/listener_pool.rb, line 82 def last_good_pid @master_state.last_good_listener_pid end
Public: Number of active listeners.
# File lib/resqued/listener_pool.rb, line 24 def size @listener_proxies.size end
Public: Initialize a new listener, run it, and record it as the current listener. Returns its ListenerProxy
.
# File lib/resqued/listener_pool.rb, line 34 def start! listener_state = ListenerState.new listener_state.options = { config_paths: @master_state.config_paths, old_workers: map { |l| l.running_workers }.flatten, listener_id: next_listener_id, } listener = ListenerProxy.new(listener_state) listener.run @master_state.listener_states[listener.pid] = listener_state @listener_proxies[listener.pid] = listener @master_state.current_listener_pid = listener.pid return listener end
Private Instance Methods
# File lib/resqued/listener_pool.rb, line 93 def next_listener_id @master_state.listeners_created += 1 end