Class: Fluent::Plugin::TailInput::WorkerCompletionWatcher
- Inherits:
-
Coolio::IOWatcher
- Object
- Coolio::IOWatcher
- Fluent::Plugin::TailInput::WorkerCompletionWatcher
- Defined in:
- lib/fluent/plugin/in_tail/worker_pool.rb
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(log: nil, &on_completion) ⇒ WorkerCompletionWatcher
constructor
A new instance of WorkerCompletionWatcher.
- #on_readable ⇒ Object
- #on_signal ⇒ Object
- #signal ⇒ Object
Constructor Details
#initialize(log: nil, &on_completion) ⇒ WorkerCompletionWatcher
Returns a new instance of WorkerCompletionWatcher.
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/fluent/plugin/in_tail/worker_pool.rb', line 240 def initialize(log: nil, &on_completion) @log = log if Fluent.windows? # Winsock select cannot monitor IO.pipe handles. Use connected # loopback sockets, as libev does for its own Windows wakeups. begin listener = TCPServer.new('127.0.0.1', 0) @writer = TCPSocket.new('127.0.0.1', listener.addr[1]) @reader = listener.accept rescue @reader&.close @writer&.close raise ensure listener&.close end else @reader, @writer = IO.pipe end super(@reader) @on_completion = on_completion end |
Instance Method Details
#close ⇒ Object
291 292 293 294 295 |
# File 'lib/fluent/plugin/in_tail/worker_pool.rb', line 291 def close detach if attached? @reader.close unless @reader.closed? @writer.close unless @writer.closed? end |
#on_readable ⇒ Object
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 |
# File 'lib/fluent/plugin/in_tail/worker_pool.rb', line 275 def on_readable notified = false begin loop do @reader.read_nonblock(4096) notified = true end rescue IO::WaitReadable return unless notified end on_signal rescue => error @log&.error 'unexpected error while processing in_tail worker completions', error: error @log&.error_backtrace end |
#on_signal ⇒ Object
271 272 273 |
# File 'lib/fluent/plugin/in_tail/worker_pool.rb', line 271 def on_signal @on_completion.call end |
#signal ⇒ Object
263 264 265 266 267 268 269 |
# File 'lib/fluent/plugin/in_tail/worker_pool.rb', line 263 def signal @writer.write_nonblock("\0") true rescue IO::WaitWritable # A full pipe already has a notification pending on the event loop. false end |