Class: SidekiqTamer::Mongo::CommandSubscriber

Inherits:
Object
  • Object
show all
Defined in:
lib/sidekiq_tamer/mongo/command_subscriber.rb

Constant Summary collapse

DATA_MODIFICATION_COMMANDS =
Set.new([
  'insert',
  'delete',
  'replace',
  'update',
  'drop',
  'rename',
  'dropDatabase',
  'invalidate',
  'createIndexes',
  'dropIndexes',
  'create',
  'modify',
  'shardCollection',
]).freeze

Instance Method Summary collapse

Instance Method Details

#failed(event) ⇒ Object



39
40
41
# File 'lib/sidekiq_tamer/mongo/command_subscriber.rb', line 39

def failed(event)
  # No implementation, just provided to fullfil the expected interface.
end

#started(event) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/sidekiq_tamer/mongo/command_subscriber.rb', line 21

def started(event)
  unless event.command.keys.any?
    return
  end

  operation = event.command.keys.any? { |key| DATA_MODIFICATION_COMMANDS.include?(key) } ? :write : :read
  mongo_server_operation = SidekiqTamer::Mongo::ServerOperation.server_operation_for(
    event.address.host, event.address.port, operation
  )
  if job_name = Thread.current[:sidekiq_tamer_job_name]
    mongo_server_operation.add_job(Object.const_get(job_name))
  end
end

#succeeded(event) ⇒ Object



35
36
37
# File 'lib/sidekiq_tamer/mongo/command_subscriber.rb', line 35

def succeeded(event)
  # No implementation, just provided to fullfil the expected interface.
end