class Taskinator::Task
Attributes
created_at[R]
next[RW]
the next task in the sequence
options[R]
process[R]
queue[R]
updated_at[R]
uuid[R]
Public Class Methods
define_job_task(process, job, args, options={})
click to toggle source
# File lib/taskinator/task.rb, line 14 def define_job_task(process, job, args, options={}) Job.new(process, job, args, options) end
define_step_task(process, method, args, options={})
click to toggle source
# File lib/taskinator/task.rb, line 10 def define_step_task(process, method, args, options={}) Step.new(process, method, args, options) end
define_sub_process_task(process, sub_process, options={})
click to toggle source
# File lib/taskinator/task.rb, line 18 def define_sub_process_task(process, sub_process, options={}) SubProcess.new(process, sub_process, options) end
new(process, options={})
click to toggle source
# File lib/taskinator/task.rb, line 33 def initialize(process, options={}) raise ArgumentError, 'process' if process.nil? || !process.is_a?(Process) @uuid = "#{process.uuid}:task:#{Taskinator.generate_uuid}" @process = process @options = options @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/task.rb, line 55 def <=>(other) uuid <=> other.uuid end
accept(visitor)
click to toggle source
# File lib/taskinator/task.rb, line 45 def accept(visitor) visitor.visit_attribute(:uuid) visitor.visit_process_reference(:process) visitor.visit_task_reference(:next) visitor.visit_args(:options) 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/task.rb, line 105 def cancel! transition(:cancelled) do self.incr_cancelled if incr_count? instrument('taskinator.task.cancelled', cancelled_payload) do cancel if respond_to?(:cancel) end end end
cancelled?()
click to toggle source
Calls superclass method
# File lib/taskinator/task.rb, line 114 def cancelled? super || process.cancelled? end
complete!()
click to toggle source
# File lib/taskinator/task.rb, line 94 def complete! transition(:completed) do self.incr_completed if incr_count? instrument('taskinator.task.completed', completed_payload) do complete if respond_to?(:complete) # notify the process that this task has completed process.task_completed(self) end end end
enqueue()
click to toggle source
# File lib/taskinator/task.rb, line 137 def enqueue raise NotImplementedError end
enqueue!()
click to toggle source
# File lib/taskinator/task.rb, line 63 def enqueue! return if paused? || cancelled? transition(:enqueued) do instrument('taskinator.task.enqueued', enqueued_payload) do enqueue end end end
fail!(error)
click to toggle source
# File lib/taskinator/task.rb, line 118 def fail!(error) transition(:failed) do self.incr_failed if incr_count? instrument('taskinator.task.failed', failed_payload(error)) do fail(error) if respond_to?(:fail) # notify the process that this task has failed process.task_failed(self, error) end end end
incr_count?()
click to toggle source
# File lib/taskinator/task.rb, line 129 def incr_count? true end
paused?()
click to toggle source
helper method
Calls superclass method
# File lib/taskinator/task.rb, line 90 def paused? super || process.paused? end
start()
click to toggle source
# File lib/taskinator/task.rb, line 141 def start raise NotImplementedError end
start!()
click to toggle source
# File lib/taskinator/task.rb, line 73 def start! return if paused? || cancelled? self.incr_processing if incr_count? transition(:processing) do instrument('taskinator.task.processing', processing_payload) do start end end end
to_s()
click to toggle source
# File lib/taskinator/task.rb, line 59 def to_s "#<#{self.class.name}:#{uuid}>" end