Class: Magent::Channel

Inherits:
GenericChannel show all
Defined in:
lib/magent/channel.rb

Instance Attribute Summary

Attributes inherited from GenericChannel

#name

Instance Method Summary collapse

Methods inherited from GenericChannel

#collection, #dequeue, #initialize, #message_count, #next_message, #queue_count

Constructor Details

This class inherits a constructor from Magent::GenericChannel

Instance Method Details

#enqueue(message, args) ⇒ Object



3
4
5
# File 'lib/magent/channel.rb', line 3

def enqueue(message, args)
  super([message, args])
end

#error_collectionObject



33
34
35
# File 'lib/magent/channel.rb', line 33

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

#error_countObject



11
12
13
# File 'lib/magent/channel.rb', line 11

def error_count
  error_collection.count()
end

#errors(conds = {}) ⇒ Object



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

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



7
8
9
# File 'lib/magent/channel.rb', line 7

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

#remove_error(error_id) ⇒ Object



24
25
26
# File 'lib/magent/channel.rb', line 24

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

#retry_error(error) ⇒ Object



28
29
30
31
# File 'lib/magent/channel.rb', line 28

def retry_error(error)
  remove_error(error["_id"])
  enqueue(error["method"], error["payload"])
end