Class: ActiveHarmony::Queue

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/active_harmony/queue.rb

Instance Method Summary collapse

Instance Method Details

#queue_pull(object_class, remote_id) ⇒ Object

Queues object for pull

Parameters:

  • Class (Class)

    of object

  • Remote (String)

    ID for object



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

Parameters:

  • Object (Object)


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_itemsArray<QueueItem>

Returns queued items

Returns:



39
40
41
# File 'lib/active_harmony/queue.rb', line 39

def queued_items
  QueueItem.where(:state => "new").all
end

#runObject

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

Returns:

  • (Boolean)

    Should run



46
47
48
# File 'lib/active_harmony/queue.rb', line 46

def should_run?
  queued_items.count > 0
end