Class: Taskinator::Task::Step

Inherits:
Task
  • Object
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 JSON

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Step.

Raises:

  • (ArgumentError)


118
119
120
121
122
123
124
125
126
127
# File 'lib/taskinator/task.rb', line 118

def initialize(name, process, method, args, options={})
  super(name, 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.



116
117
118
# File 'lib/taskinator/task.rb', line 116

def args
  @args
end

#definitionObject (readonly)

Returns the value of attribute definition.



114
115
116
# File 'lib/taskinator/task.rb', line 114

def definition
  @definition
end

#methodObject (readonly)

Returns the value of attribute method.



115
116
117
# File 'lib/taskinator/task.rb', line 115

def method
  @method
end

Instance Method Details

#accept(visitor) ⇒ Object



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

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)


140
141
142
# File 'lib/taskinator/task.rb', line 140

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

#executorObject



129
130
131
# File 'lib/taskinator/task.rb', line 129

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

#startObject



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

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