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

#next, #options, #process, #queue, #uuid

Instance Method Summary collapse

Methods inherited from Taskinator::Task

#<=>, base_key, #cancelled?, define_job_task, define_step_task, define_sub_process_task, #enqueue, #on_completed_entry, #on_failed_entry, #paused?, #reload, #to_s

Methods included from Persistence

add_process_to_list, deserialize, included, list_key, serialize

Constructor Details

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

Returns a new instance of Step.

Raises:

  • (ArgumentError)


135
136
137
138
139
140
141
142
143
144
# File 'lib/taskinator/task.rb', line 135

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.



133
134
135
# File 'lib/taskinator/task.rb', line 133

def args
  @args
end

#definitionObject (readonly)

Returns the value of attribute definition.



131
132
133
# File 'lib/taskinator/task.rb', line 131

def definition
  @definition
end

#methodObject (readonly)

Returns the value of attribute method.



132
133
134
# File 'lib/taskinator/task.rb', line 132

def method
  @method
end

Instance Method Details

#accept(visitor) ⇒ Object



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

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

#can_complete_task?Boolean

NOTE: this _does not_ work when checking out-of-process

Returns:

  • (Boolean)


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

def can_complete_task?
  defined?(@is_complete) && @is_complete
end

#executorObject



146
147
148
# File 'lib/taskinator/task.rb', line 146

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

#startObject



150
151
152
153
154
155
156
# File 'lib/taskinator/task.rb', line 150

def start
  # ASSUMPTION: when the method returns, the task is considered to be complete
  Taskinator.instrumenter.instrument(:execute_step_task, :uuid => uuid) do
    executor.send(method, *args)
  end
  @is_complete = true
end