Module: Magent::Failure

Included in:
GenericChannel
Defined in:
lib/magent/failure.rb

Instance Method Summary collapse

Instance Method Details

#enqueue_error(error) ⇒ Object



38
39
40
41
# File 'lib/magent/failure.rb', line 38

def enqueue_error(error)
  enqueue(error["message"], 1)
  remove_error(error["_id"])
end

#error_collectionObject



43
44
45
# File 'lib/magent/failure.rb', line 43

def error_collection
  @error_collection ||= Magent.database.collection("#{@name}.errors")
end

#error_countObject



12
13
14
# File 'lib/magent/failure.rb', line 12

def error_count
  error_collection.count()
end

#errors(conds = {}) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/magent/failure.rb', line 16

def errors(conds = {})
  page = conds.delete(:page) || 1
  per_page = conds.delete(:per_page) || 10

  error_collection.find({}, {:skip => (page-1)*per_page,
                             :limit => per_page,
                             :sort => [["created_at", -1]]})
end

#failed(info) ⇒ Object



3
4
5
6
7
8
9
10
# File 'lib/magent/failure.rb', line 3

def failed(info)
  error_collection.save(info.merge({
    :_id => generate_uid,
    :channel => @name,
    :channel_class => self.class.to_s,
    :created_at => Time.now.utc
  }))
end

#remove_error(error_id) ⇒ Object



25
26
27
# File 'lib/magent/failure.rb', line 25

def remove_error(error_id)
  self.error_collection.remove(:_id => error_id)
end

#retry_error(error) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/magent/failure.rb', line 29

def retry_error(error)
  begin
    process!(error["message"])
    remove_error(error["_id"])
  rescue => e
    $stderr.puts "Failed to retry error #{error['_id']}: #{e.message}"
  end
end