class Taskinator::Process

Attributes

created_at[R]
definition[R]
options[R]
parent[R]

in the case of sub process tasks, the containing task

queue[R]
scope[R]
updated_at[R]
uuid[R]

Public Class Methods

define_concurrent_process_for(definition, complete_on=CompleteOn::Default, options={}) click to toggle source
# File lib/taskinator/process.rb, line 17
def define_concurrent_process_for(definition, complete_on=CompleteOn::Default, options={})
  Process::Concurrent.new(definition, complete_on, options)
end
define_sequential_process_for(definition, options={}) click to toggle source
# File lib/taskinator/process.rb, line 13
def define_sequential_process_for(definition, options={})
  Process::Sequential.new(definition, options)
end
new(definition, options={}) click to toggle source
# File lib/taskinator/process.rb, line 33
def initialize(definition, options={})
  raise ArgumentError, 'definition' if definition.nil?
  raise ArgumentError, "#{definition.name} does not extend the #{Definition.name} module" unless definition.kind_of?(Definition)

  @uuid = options.delete(:uuid) || Taskinator.generate_uuid
  @definition = definition
  @options = options
  @scope = options.delete(:scope)
  @queue = options.delete(:queue)
  @created_at = Time.now.utc
  @updated_at = created_at
  @current_state = :initial
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/taskinator/process.rb, line 73
def <=>(other)
  uuid <=> other.uuid
end
accept(visitor) click to toggle source
# File lib/taskinator/process.rb, line 61
def accept(visitor)
  visitor.visit_attribute(:uuid)
  visitor.visit_task_reference(:parent)
  visitor.visit_type(:definition)
  visitor.visit_tasks(tasks)
  visitor.visit_args(:options)
  visitor.visit_attribute(:scope)
  visitor.visit_attribute(:queue)
  visitor.visit_attribute_time(:created_at)
  visitor.visit_attribute_time(:updated_at)
end
cancel!() click to toggle source
# File lib/taskinator/process.rb, line 141
def cancel!
  transition(:cancelled) do
    instrument('taskinator.process.cancelled', cancelled_payload) do
      cancel if respond_to?(:cancel)
    end
  end
end
complete!() click to toggle source
# File lib/taskinator/process.rb, line 121
def complete!
  transition(:completed) do
    instrument('taskinator.process.completed', completed_payload) do
      complete if respond_to?(:complete)
      # notify the parent task (if there is one) that this process has completed
      # note: parent may be a proxy, so explicity check for nil?
      unless parent.nil?
        parent.complete!
      else
        cleanup
      end
    end
  end
end
enqueue() click to toggle source
# File lib/taskinator/process.rb, line 169
def enqueue
  raise NotImplementedError
end
enqueue!() click to toggle source
# File lib/taskinator/process.rb, line 81
def enqueue!
  return if paused? || cancelled?

  transition(:enqueued) do
    instrument('taskinator.process.enqueued', enqueued_payload) do
      enqueue
    end
  end
end
fail!(error) click to toggle source
# File lib/taskinator/process.rb, line 149
def fail!(error)
  transition(:failed) do
    instrument('taskinator.process.failed', failed_payload(error)) do
      fail(error) if respond_to?(:fail)
      # notify the parent task (if there is one) that this process has failed
      # note: parent may be a proxy, so explicity check for nil?
      parent.fail!(error) unless parent.nil?
    end
  end
end
no_tasks_defined?() click to toggle source
# File lib/taskinator/process.rb, line 57
def no_tasks_defined?
  tasks.empty?
end
parent=(value) click to toggle source
# File lib/taskinator/process.rb, line 47
def parent=(value)
  @parent = value
  # update the uuid to be "scoped" within the parent task
  @uuid = "#{@parent.uuid}:subprocess"
end
pause!() click to toggle source
# File lib/taskinator/process.rb, line 101
def pause!
  return unless enqueued? || processing?

  transition(:paused) do
    instrument('taskinator.process.paused', paused_payload) do
      pause if respond_to?(:pause)
    end
  end
end
resume!() click to toggle source
# File lib/taskinator/process.rb, line 111
def resume!
  return unless paused?

  transition(:processing) do
    instrument('taskinator.process.resumed', resumed_payload) do
      resume if respond_to?(:resume)
    end
  end
end
start() click to toggle source
# File lib/taskinator/process.rb, line 173
def start
  raise NotImplementedError
end
start!() click to toggle source
# File lib/taskinator/process.rb, line 91
def start!
  return if paused? || cancelled?

  transition(:processing) do
    instrument('taskinator.process.processing', processing_payload) do
      start
    end
  end
end
task_completed(task) click to toggle source
# File lib/taskinator/process.rb, line 177
def task_completed(task)
  raise NotImplementedError
end
task_failed(task, error) click to toggle source
# File lib/taskinator/process.rb, line 160
def task_failed(task, error)
  # for now, fail this process
  fail!(error)
end
tasks() click to toggle source
# File lib/taskinator/process.rb, line 53
def tasks
  @tasks ||= Tasks.new
end
tasks_completed?() click to toggle source
# File lib/taskinator/process.rb, line 136
def tasks_completed?
  # TODO: optimize this
  tasks.all?(&:completed?)
end
to_s() click to toggle source
# File lib/taskinator/process.rb, line 77
def to_s
  "#<#{self.class.name}:#{uuid}>"
end