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, #definition, #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)


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

def initialize(process, method, args, options={})
  super(process, options)

  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.



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

def args
  @args
end

#methodObject (readonly)

Returns the value of attribute method.



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

def method
  @method
end

Instance Method Details

#accept(visitor) ⇒ Object



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

def accept(visitor)
  super
  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



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

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

#inspectObject



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

def inspect
  %(#<#{self.class.name}:0x#{self.__id__.to_s(16)} uuid="#{uuid}", definition=:#{definition}, 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