Class: Async::Background::Queue::SocketNotifier
- Inherits:
-
Object
- Object
- Async::Background::Queue::SocketNotifier
- Includes:
- Clock
- 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
- DEAD_WORKER_TTL =
5.0- WAKE_BYTE =
"\x01".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.
24 25 26 27 28 29 30 |
# File 'lib/async/background/queue/socket_notifier.rb', line 24 def initialize(socket_dir:, total_workers:) @socket_dir = socket_dir @total_workers = total_workers @paths = build_paths @dead_until = Array.new([@total_workers, 0].max, 0.0) @cursor = 0 end |
Instance Method Details
#notify_all ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/async/background/queue/socket_notifier.rb', line 32 def notify_all return false if @total_workers <= 0 now = monotonic_now start = advance_cursor @total_workers.times do |offset| index = (start + offset) % @total_workers return true if notify_one(index, now) end false end |