Module: MergingQueue::QueuedTask::ClassMethods

Defined in:
lib/merging-queue/queued_task.rb

Instance Method Summary collapse

Instance Method Details

#accumulate_changes(search_result) ⇒ Object

—- add up all actors, act_objects and act_targets in the search results.

it does not matter what is where


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/merging-queue/queued_task.rb', line 46

def accumulate_changes(search_result)
  act_targets    = []
  act_target_ids = []
  act_objects    = []
  act_object_ids = []

  _actor = search_result.first.actor

  search_result.each do |result|
    result.update_attributes(:state => 'pending')

    act_object = result.act_object
    act_target = result.act_target

    if act_object != nil && !act_object_ids.include?(act_object.id)
      act_objects    << act_object
      act_object_ids << act_object.id

    end

    if act_target != nil && !act_target_ids.include?(act_target.id)
      act_targets    << act_target
      act_target_ids << act_target.id

    end

  end

  {:actor => _actor, :act_objects => act_objects, :act_object_ids => act_object_ids,
   :act_targets => act_targets, :act_target_ids => act_target_ids}
end

#poll_for_changesObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/merging-queue/queued_task.rb', line 18

def poll_for_changes()
  #if block_given?

  ::QueuedTask.where('state = ? AND publish_on <= ?', 'initial', Time.now).distinct(:actor_id).each do |actor_id|

    ::QueuedTask.where('state = ? AND actor_id = ? AND publish_on <= ?', 'initial', actor_id, Time.now).select(:verb).uniq.each do |verb|

      changes_for_actor =  ::QueuedTask.where(:actor_id => actor_id, :state => 'initial', :verb => verb['verb'].to_s)

      begin
        yield  verb, accumulate_changes(changes_for_actor)

        changes_for_actor.destroy_all

      rescue ActiveRecord::RecordNotFound
      end


    end


  end
end

#publish(verb, cur_publish_on, data) ⇒ MergingQueue::QueuedTask2

Publishes an queued_task using an queued_task name and data

Parameters:

  • verb (String)

    The verb of the queued_task

  • data (Hash)

    The data to initialize the queued_task with.

Returns:

  • (MergingQueue::QueuedTask2)

    An QueuedTask instance with data



102
103
104
# File 'lib/merging-queue/queued_task.rb', line 102

def publish(verb, cur_publish_on, data)
  new.publish({:verb => verb, :publish_on => cur_publish_on}.merge(data))
end

#queued_task(name, &block) ⇒ Definition

Defines a new QueuedTask2 type and registers a definition

Examples:

Define a new queued_task

queued_task(:enquiry) do
  actor :user, :cache => [:full_name]
  act_object :enquiry, :cache => [:subject]
  act_target :listing, :cache => [:title]
end

Parameters:

  • name (String)

    The name of the queued_task

Returns:

  • (Definition)

    Returns the registered definition



90
91
92
93
94
# File 'lib/merging-queue/queued_task.rb', line 90

def queued_task(name, &block)
  definition = MergingQueue::DefinitionDSL.new(name)
  definition.instance_eval(&block)
  MergingQueue::Definition.register(definition)
end