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

#<=>, base_key, #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, 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)


165
166
167
168
169
170
171
172
173
174
# File 'lib/taskinator/task.rb', line 165

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.



163
164
165
# File 'lib/taskinator/task.rb', line 163

def args
  @args
end

#definitionObject (readonly)

Returns the value of attribute definition.



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

def definition
  @definition
end

#methodObject (readonly)

Returns the value of attribute method.



162
163
164
# File 'lib/taskinator/task.rb', line 162

def method
  @method
end

Instance Method Details

#accept(visitor) ⇒ Object



192
193
194
195
196
197
# File 'lib/taskinator/task.rb', line 192

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

#enqueueObject



176
177
178
# File 'lib/taskinator/task.rb', line 176

def enqueue
  Taskinator.queue.enqueue_task(self)
end

#executorObject



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

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

#inspectObject



203
204
205
# File 'lib/taskinator/task.rb', line 203

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

#startObject



180
181
182
183
184
185
186
187
188
189
190
# File 'lib/taskinator/task.rb', line 180

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