Class: Taskinator::Process::Concurrent

Inherits:
Taskinator::Process show all
Defined in:
lib/taskinator/process.rb

Instance Attribute Summary collapse

Attributes inherited from Taskinator::Process

#definition, #options, #parent, #uuid

Instance Method Summary collapse

Methods inherited from Taskinator::Process

#<=>, base_key, define_concurrent_process_for, define_sequential_process_for, #enqueue, #on_completed_entry, #tasks, #to_s

Methods included from Taskinator::Persistence

included

Constructor Details

#initialize(definition, complete_on = CompleteOn::Default, options = {}) ⇒ Concurrent

Returns a new instance of Concurrent.



142
143
144
145
# File 'lib/taskinator/process.rb', line 142

def initialize(definition, complete_on=CompleteOn::Default, options={})
  super(definition, options)
  @complete_on = complete_on
end

Instance Attribute Details

#complete_onObject (readonly)

Returns the value of attribute complete_on.



140
141
142
# File 'lib/taskinator/process.rb', line 140

def complete_on
  @complete_on
end

Instance Method Details

#accept(visitor) ⇒ Object



170
171
172
173
# File 'lib/taskinator/process.rb', line 170

def accept(visitor)
  super
  visitor.visit_attribute(:complete_on)
end

#startObject



147
148
149
150
151
152
153
# File 'lib/taskinator/process.rb', line 147

def start
  if tasks.any?
    tasks.each(&:enqueue!)
  else
    complete! # weren't any tasks to start with
  end
end

#task_completed(task) ⇒ Object



155
156
157
158
159
# File 'lib/taskinator/process.rb', line 155

def task_completed(task)
  # when complete on first, then don't bother with subsequent tasks completing
  return if completed?
  complete! if can_complete?
end

#tasks_completed?(*args) ⇒ Boolean

Returns:

  • (Boolean)


161
162
163
164
165
166
167
168
# File 'lib/taskinator/process.rb', line 161

def tasks_completed?(*args)
  # TODO: optimize this
  if (complete_on == CompleteOn::First)
    tasks.any?(&:completed?)
  else
    tasks.all?(&:completed?)
  end
end