Class: Euston::Daemons::Pipeline::CommandProcessor::FailedMessage

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

Instance Method Summary collapse

Constructor Details

#initialize(mongodb) ⇒ FailedMessage

Returns a new instance of FailedMessage.



6
7
8
9
10
11
12
# File 'lib/euston-daemons/pipeline/lib/command_processor/failed_message.rb', line 6

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

  @collection = mongodb.collection name
  @collection.ensure_index [ ['failure_timestamp', Mongo::ASCENDING] ], :unique => false, :name => 'failed_messages_failure_timestamp_index'
end

Instance Method Details

#find_allObject



18
19
20
# File 'lib/euston-daemons/pipeline/lib/command_processor/failed_message.rb', line 18

def find_all
  @collection.find({}, { :sort => [ 'failure_timestamp', Mongo::DESCENDING ] })
end

#get_by_id(id) ⇒ Object



14
15
16
# File 'lib/euston-daemons/pipeline/lib/command_processor/failed_message.rb', line 14

def get_by_id id
  @collection.find_one({ '_id' => id })
end

#log_failure(failure) ⇒ Object



22
23
24
25
26
27
# File 'lib/euston-daemons/pipeline/lib/command_processor/failed_message.rb', line 22

def log_failure failure
  failure.recursive_stringify_keys!
  failure['_id'] = failure.delete 'message_id'

  @collection.save(failure, :safe => { :fsync => true })
end

#remove_by_id(id) ⇒ Object



29
30
31
# File 'lib/euston-daemons/pipeline/lib/command_processor/failed_message.rb', line 29

def remove_by_id id
  @collection.remove({ '_id' => id }, :safe => { :fsync => true })
end