Class: Sixty::Instrument::Mongo::Subscriber

Inherits:
Object
  • Object
show all
Defined in:
lib/sixty/instrument/mongo.rb

Overview

The monitoring contract: three methods, none of which may raise into the driver. A subscriber that throws would fail the application's query.

Instance Method Summary collapse

Instance Method Details

#failed(event) ⇒ Object



421
422
423
424
425
426
# File 'lib/sixty/instrument/mongo.rb', line 421

def failed(event)
  # `event.message` is the server's error text. It is used as the error
  # message and never as part of the operation's identity, so a failure
  # that quotes a value cannot mint an operation from it.
  finish(event, CommandFailed.new(event.message.to_s))
end

#started(event) ⇒ Object



398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
# File 'lib/sixty/instrument/mongo.rb', line 398

def started(event)
  return unless Sixty.enabled?

  command_name = event.command_name.to_s
  # Not an operation, but the end of one: the application stopped
  # reading a cursor and the driver is telling the server so.
  if command_name == 'killCursors'
    Mongo.kill_cursors(Array(event.command['cursors']).map { |id| Mongo.cursor_id_of(id) }.compact)
    return
  end
  return if IGNORED_COMMANDS.include?(command_name)

  in_flight = (Thread.current[KEY] ||= {})
  in_flight.clear if in_flight.size >= MAX_IN_FLIGHT
  in_flight[event.request_id] = Mongo.describe(event)
rescue StandardError
  nil
end

#succeeded(event) ⇒ Object



417
418
419
# File 'lib/sixty/instrument/mongo.rb', line 417

def succeeded(event)
  finish(event, nil)
end