Class: Magent::GenericChannel
- Inherits:
-
Object
- Object
- Magent::GenericChannel
- Defined in:
- lib/magent/generic_channel.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #collection ⇒ Object
- #dequeue ⇒ Object
- #enqueue(message) ⇒ Object
-
#initialize(name) ⇒ GenericChannel
constructor
A new instance of GenericChannel.
- #message_count ⇒ Object
- #next_message ⇒ Object
- #queue_count ⇒ Object
Constructor Details
#initialize(name) ⇒ GenericChannel
5 6 7 |
# File 'lib/magent/generic_channel.rb', line 5 def initialize(name) @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/magent/generic_channel.rb', line 3 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
21 22 23 24 25 |
# File 'lib/magent/generic_channel.rb', line 21 def dequeue if m = self. m["message"] end end |
#enqueue(message) ⇒ Object
9 10 11 |
# File 'lib/magent/generic_channel.rb', line 9 def enqueue() collection.save({:_id => generate_uid, :message => , :priority => 3, :created_at => Time.now.to_i}) end |
#message_count ⇒ Object
13 14 15 |
# File 'lib/magent/generic_channel.rb', line 13 def collection.count # TODO: number of processed messages (create a collection for stats) end |
#next_message ⇒ Object
27 28 29 30 31 32 |
# File 'lib/magent/generic_channel.rb', line 27 def Magent.database.command(BSON::OrderedHash[:findandmodify, @name, :sort, [{:priority => -1}, {:created_at => 1}], :remove, true ])["value"] end |
#queue_count ⇒ Object
17 18 19 |
# File 'lib/magent/generic_channel.rb', line 17 def queue_count collection.count end |