Method: Arborist::Monitor::ConnectionBatching::BatchRunner#run

Defined in:
lib/arborist/monitor/connection_batching.rb

#run(&block) ⇒ Object

Run the batch runner, yielding to the specified block as each connection becomes ready.



193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/arborist/monitor/connection_batching.rb', line 193

def run( &block )
  self.start = Time.now

  until self.finished?
    self.log.debug "Getting the status of %d connections." %
      [ self.current_batch.length ]

    self.fill_batch
    wait_seconds = self.remove_timedout_connections
    ready = self.wait_for_ready_connections( wait_seconds )

    # If the select returns ready sockets
    #   Build successful status for each ready socket
    now = Time.now
    ready.each do |sock|
      conn_hash = self.remove_socket( sock ) or
        raise "Ready socket %p was not in the current batch!" % [ sock ]

      identifier, start = conn_hash.values_at( :identifier, :start )
      duration = now - start

      results[ identifier ] = block.call( conn_hash, duration )
    end if ready
  end

  return Time.now - self.start
end