Class: Async::Background::Queue::SocketNotifier
- Inherits:
-
Object
- Object
- Async::Background::Queue::SocketNotifier
- Defined in:
- lib/async/background/queue/socket_notifier.rb
Constant Summary collapse
- UNAVAILABLE =
Errors that indicate a worker is unavailable - silently skip and try the next.
[ Errno::ENOENT, # Socket file doesn't exist (worker hasn't started yet) Errno::ECONNREFUSED, # File exists but no one listening (worker died) Errno::EPIPE, # Connection broken during write Errno::ECONNRESET # Connection reset by peer ].freeze
Instance Method Summary collapse
-
#initialize(socket_dir:, total_workers:) ⇒ SocketNotifier
constructor
A new instance of SocketNotifier.
- #notify_all ⇒ Object
Constructor Details
#initialize(socket_dir:, total_workers:) ⇒ SocketNotifier
Returns a new instance of SocketNotifier.
17 18 19 20 |
# File 'lib/async/background/queue/socket_notifier.rb', line 17 def initialize(socket_dir:, total_workers:) @socket_dir = socket_dir @total_workers = total_workers end |
Instance Method Details
#notify_all ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/async/background/queue/socket_notifier.rb', line 22 def notify_all return if @total_workers <= 0 start = rand(@total_workers) @total_workers.times do |i| worker_index = ((start + i) % @total_workers) + 1 return if notify_one(worker_index) end end |