Class: Magent::GenericChannel
- Inherits:
-
Object
- Object
- Magent::GenericChannel
show all
- Includes:
- Failure
- Defined in:
- lib/magent/generic_channel.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Failure
#enqueue_error, #error_collection, #error_count, #errors, #failed, #remove_error, #retry_error
Constructor Details
Returns a new instance of GenericChannel.
7
8
9
|
# File 'lib/magent/generic_channel.rb', line 7
def initialize(name)
@name = "magent.#{name}"
end
|
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
5
6
7
|
# File 'lib/magent/generic_channel.rb', line 5
def name
@name
end
|
Instance Method Details
#collection ⇒ Object
34
35
36
|
# File 'lib/magent/generic_channel.rb', line 34
def collection
@collection ||= Magent.database.collection(@name)
end
|
#dequeue ⇒ Object
23
24
25
26
27
|
# File 'lib/magent/generic_channel.rb', line 23
def dequeue
if m = self.next_message
m["message"]
end
end
|
#enqueue(message, priority = 3) ⇒ Object
11
12
13
|
# File 'lib/magent/generic_channel.rb', line 11
def enqueue(message, priority = 3)
collection.save({:_id => generate_uid, :message => message, :priority => priority, :created_at => Time.now.to_i})
end
|
#message_count ⇒ Object
15
16
17
|
# File 'lib/magent/generic_channel.rb', line 15
def message_count
collection.count end
|
#next_message ⇒ Object
29
30
31
32
|
# File 'lib/magent/generic_channel.rb', line 29
def next_message
collection.find_and_modify(:sort => [[:priority, Mongo::ASCENDING], [:created_at, Mongo::DESCENDING]],
:remove => true) rescue {}
end
|
#queue_count ⇒ Object
19
20
21
|
# File 'lib/magent/generic_channel.rb', line 19
def queue_count
collection.count
end
|