Class: Taskinator::Task::Step

Inherits:
Taskinator::Task show all
Defined in:
lib/taskinator/task.rb

Overview

a task which invokes the specified method on the definition the args must be intrinsic types, since they are serialized to YAML

Instance Attribute Summary collapse

Attributes inherited from Taskinator::Task

#created_at, #next, #options, #process, #queue, #updated_at, #uuid

Instance Method Summary collapse

Methods inherited from Taskinator::Task

#<=>, #cancel!, #cancelled?, #complete!, define_job_task, define_step_task, define_sub_process_task, #enqueue!, #fail!, #incr_count?, #paused?, #start!, #to_s

Methods included from Instrumentation

#cancelled_payload, #completed_payload, #enqueued_payload, #failed_payload, #instrument, #paused_payload, #processing_payload, #resumed_payload

Methods included from Persistence

add_process_to_list, deserialize, included, processes_list_key, serialize

Methods included from Workflow

#current_state, #current_state=, #transition

Constructor Details

#initialize(process, method, args, options = {}) ⇒ Step

Returns a new instance of Step.

Raises:

  • (ArgumentError)


162
163
164
165
166
167
168
169
170
171
# File 'lib/taskinator/task.rb', line 162

def initialize(process, method, args, options={})
  super(process, options)
  @definition = process.definition  # for convenience

  raise ArgumentError, 'method' if method.nil?
  raise NoMethodError, method unless executor.respond_to?(method)

  @method = method
  @args = args
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



160
161
162
# File 'lib/taskinator/task.rb', line 160

def args
  @args
end

#definitionObject (readonly)

Returns the value of attribute definition.



158
159
160
# File 'lib/taskinator/task.rb', line 158

def definition
  @definition
end

#methodObject (readonly)

Returns the value of attribute method.



159
160
161
# File 'lib/taskinator/task.rb', line 159

def method
  @method
end

Instance Method Details

#accept(visitor) ⇒ Object



189
190
191
192
193
194
# File 'lib/taskinator/task.rb', line 189

def accept(visitor)
  super
  visitor.visit_type(:definition)
  visitor.visit_attribute(:method)
  visitor.visit_args(:args)
end

#enqueueObject



173
174
175
# File 'lib/taskinator/task.rb', line 173

def enqueue
  Taskinator.queue.enqueue_task(self)
end

#executorObject



196
197
198
# File 'lib/taskinator/task.rb', line 196

def executor
  @executor ||= Taskinator::Executor.new(@definition, self)
end

#inspectObject



200
201
202
# File 'lib/taskinator/task.rb', line 200

def inspect
  %(#<#{self.class.name}:0x#{self.__id__.to_s(16)} uuid="#{uuid}", method=:#{method}, args=#{args}, current_state=:#{current_state}>)
end

#startObject



177
178
179
180
181
182
183
184
185
186
187
# File 'lib/taskinator/task.rb', line 177

def start
  executor.send(method, *args)
  # ASSUMPTION: when the method returns, the task is considered to be complete
  complete!

rescue => e
  Taskinator.logger.error(e)
  Taskinator.logger.debug(e.backtrace)
  fail!(e)
  raise e
end