Class: ActiveHarmony::Queue
- Inherits:
-
Object
- Object
- ActiveHarmony::Queue
- Includes:
- Singleton
- Defined in:
- lib/active_harmony/queue.rb
Instance Method Summary collapse
-
#queue_pull(object_class, remote_id) ⇒ Object
Queues object for pull.
-
#queue_push(object) ⇒ Object
Queues object for push.
-
#queued_items ⇒ Array<QueueItem>
Returns queued items.
-
#run ⇒ Object
Runs queue.
-
#should_run? ⇒ Boolean
Returns true if there are any items in queue.
Instance Method Details
#queue_pull(object_class, remote_id) ⇒ Object
Queues object for pull
20 21 22 23 24 25 26 |
# File 'lib/active_harmony/queue.rb', line 20 def queue_pull(object_class, remote_id) queue_item = QueueItem.new( :kind => "pull", :object_type => object_class.name, :object_remote_id => remote_id, :state => "new" ) queue_item.save end |
#queue_push(object) ⇒ Object
Queues object for push
8 9 10 11 12 13 14 |
# File 'lib/active_harmony/queue.rb', line 8 def queue_push(object) queue_item = QueueItem.new( :kind => "push", :object_type => object.class.name, :object_local_id => object.id, :state => "new" ) queue_item.save end |
#queued_items ⇒ Array<QueueItem>
Returns queued items
39 40 41 |
# File 'lib/active_harmony/queue.rb', line 39 def queued_items QueueItem.where(:state => "new").all end |
#run ⇒ Object
Runs queue
30 31 32 33 34 |
# File 'lib/active_harmony/queue.rb', line 30 def run queued_items.each do |item| item.process_item end end |
#should_run? ⇒ Boolean
Returns true if there are any items in queue
46 47 48 |
# File 'lib/active_harmony/queue.rb', line 46 def should_run? queued_items.count > 0 end |