Class: Taski::Execution::TaskWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/taski/execution/task_wrapper.rb

Constant Summary collapse

STATE_PENDING =
:pending
STATE_RUNNING =
:running
STATE_COMPLETED =
:completed

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(task, registry:, coordinator:) ⇒ TaskWrapper

Returns a new instance of TaskWrapper.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/taski/execution/task_wrapper.rb', line 32

def initialize(task, registry:, coordinator:)
  @task = task
  @registry = registry
  @coordinator = coordinator
  @result = nil
  @clean_result = nil
  @error = nil
  @monitor = Monitor.new
  @condition = @monitor.new_cond
  @clean_condition = @monitor.new_cond
  @state = STATE_PENDING
  @clean_state = STATE_PENDING
  @timing = nil

  register_with_progress_display
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object (private)



242
243
244
245
246
247
248
# File 'lib/taski/execution/task_wrapper.rb', line 242

def method_missing(method_name, *args, &block)
  if @task.class.method_defined?(method_name)
    get_exported_value(method_name)
  else
    super
  end
end

Instance Attribute Details

#resultObject (readonly)

Returns the value of attribute result.



26
27
28
# File 'lib/taski/execution/task_wrapper.rb', line 26

def result
  @result
end

#taskObject (readonly)

Returns the value of attribute task.



26
27
28
# File 'lib/taski/execution/task_wrapper.rb', line 26

def task
  @task
end

Instance Method Details

#cleanObject

Returns The result of cleanup.

Returns:

  • (Object)

    The result of cleanup



57
58
59
60
# File 'lib/taski/execution/task_wrapper.rb', line 57

def clean
  execute_clean_if_needed
  @clean_result
end

#get_exported_value(method_name) ⇒ Object

Returns The exported value.

Parameters:

  • method_name (Symbol)

    The name of the exported method

Returns:

  • (Object)

    The exported value

Raises:

  • (@error)


64
65
66
67
68
# File 'lib/taski/execution/task_wrapper.rb', line 64

def get_exported_value(method_name)
  execute_task_if_needed
  raise @error if @error # steep:ignore
  @task.public_send(method_name)
end

#runObject

Returns The result of task execution.

Returns:

  • (Object)

    The result of task execution

Raises:

  • (@error)


50
51
52
53
54
# File 'lib/taski/execution/task_wrapper.rb', line 50

def run
  execute_task_if_needed
  raise @error if @error # steep:ignore
  @result
end