Class: Euston::Daemons::Pipeline::CommandLogger::Log

Inherits:
Object
  • Object
show all
Defined in:
lib/euston-daemons/pipeline/lib/command_logger/log.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mongodb) ⇒ Log

Returns a new instance of Log.



6
7
8
9
10
11
# File 'lib/euston-daemons/pipeline/lib/command_logger/log.rb', line 6

def initialize mongodb
  @name = 'command_log'
  mongodb.create_collection @name unless mongodb.collection_names.include? @name

  @collection = mongodb.collection @name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



13
14
15
# File 'lib/euston-daemons/pipeline/lib/command_logger/log.rb', line 13

def name
  @name
end

Instance Method Details

#write_command(command) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/euston-daemons/pipeline/lib/command_logger/log.rb', line 15

def write_command command
  timestamp = Time.now.to_f

  doc = { 'command_id'            => command[:headers][:id],
          'type'                  => command[:headers][:type],
          'version'               => command[:headers][:version],
          'timestamp'             => timestamp,
          'timestamp_for_humans'  => Time.at(timestamp),
          'json'                  => ActiveSupport::JSON.encode(command) }

  @collection.insert doc
end