class Taskinator::Process::Concurrent

Attributes

complete_on[R]
concurrency_method[R]

Public Class Methods

new(definition, complete_on=CompleteOn::Default, options={}) click to toggle source
Calls superclass method Taskinator::Process::new
# File lib/taskinator/process.rb, line 227
def initialize(definition, complete_on=CompleteOn::Default, options={})
  super(definition, options)
  @complete_on = complete_on
  @concurrency_method = options.delete(:concurrency_method) || :thread
end

Public Instance Methods

accept(visitor) click to toggle source
Calls superclass method Taskinator::Process#accept
# File lib/taskinator/process.rb, line 289
def accept(visitor)
  super
  visitor.visit_attribute_enum(:complete_on, CompleteOn)
end
enqueue() click to toggle source
# File lib/taskinator/process.rb, line 233
def enqueue
  if tasks.empty?
    complete! # weren't any tasks to start with
  else
    Taskinator.statsd_client.count("taskinator.#{definition.name.underscore.parameterize}.pending", tasks.count)
    Taskinator.logger.info("Enqueuing #{tasks.count} tasks for process '#{uuid}'.")
    tasks.each(&:enqueue!)
  end
end
inspect() click to toggle source
# File lib/taskinator/process.rb, line 294
def inspect
  %(#<#{self.class.name}:0x#{self.__id__.to_s(16)} uuid="#{uuid}", state=:#{current_state}, complete_on=:#{complete_on}, tasks=[#{tasks.inspect}]>)
end
start() click to toggle source

this method only called in-process (usually from the console)

# File lib/taskinator/process.rb, line 244
def start
  if tasks.empty?
    complete! # weren't any tasks to start with
  else
    if concurrency_method == :fork
      tasks.each do |task|
        fork do
          task.start!
        end
      end
      Process.waitall
    else
      threads = tasks.map do |task|
        Thread.new do
          task.start!
        end
      end
      ThreadsWait.all_waits(*threads)
    end
  end
end
task_completed(task) click to toggle source
# File lib/taskinator/process.rb, line 266
def task_completed(task)
  # deincrement the count of pending concurrent tasks
  pending = deincr_pending_tasks

  Taskinator.statsd_client.count("taskinator.#{definition.name.underscore.parameterize}.pending", pending)
  Taskinator.logger.info("Completed task for process '#{uuid}'. Pending is #{pending}.")

  # when complete on first, then don't bother with subsequent tasks completing
  if (complete_on == CompleteOn::First)
    complete! unless completed?
  else
    complete! if pending < 1
  end
end
tasks_completed?() click to toggle source
Calls superclass method Taskinator::Process#tasks_completed?
# File lib/taskinator/process.rb, line 281
def tasks_completed?
  if (complete_on == CompleteOn::First)
    tasks.any?(&:completed?)
  else
    super # all
  end
end