Class: Choria::Orchestrator::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/choria/orchestrator/task.rb,
lib/choria/orchestrator/task/result_set.rb

Defined Under Namespace

Classes: Error, NoNodesLeftError, ResultSet

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(orchestrator:, id: nil, name: nil, input: {}, environment: 'production') ⇒ Task

Returns a new instance of Task.



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/choria/orchestrator/task.rb', line 16

def initialize(orchestrator:, id: nil, name: nil, input: {}, environment: 'production')
  @id = id
  @name = name
  @environment = environment
  @orchestrator = orchestrator
  return if @name.nil?

  @input = default_input.merge input
  logger.debug "Task inputs: #{input}"
  validate_inputs
end

Instance Attribute Details

#environmentObject (readonly)

Returns the value of attribute environment.



14
15
16
# File 'lib/choria/orchestrator/task.rb', line 14

def environment
  @environment
end

#idObject (readonly)

Returns the value of attribute id.



14
15
16
# File 'lib/choria/orchestrator/task.rb', line 14

def id
  @id
end

#inputObject (readonly)

Returns the value of attribute input.



14
15
16
# File 'lib/choria/orchestrator/task.rb', line 14

def input
  @input
end

#nameObject (readonly)

Returns the value of attribute name.



14
15
16
# File 'lib/choria/orchestrator/task.rb', line 14

def name
  @name
end

Instance Method Details

#filesObject



32
33
34
# File 'lib/choria/orchestrator/task.rb', line 32

def files
  ['files'].to_json
end

#metadataObject



28
29
30
# File 'lib/choria/orchestrator/task.rb', line 28

def 
  @metadata ||= 
end

#on_result(&block) ⇒ Object



59
60
61
# File 'lib/choria/orchestrator/task.rb', line 59

def on_result(&block)
  @on_result = ->(result, count, total_count) { block.call(result, count, total_count) }
end

#resultsObject



36
37
38
# File 'lib/choria/orchestrator/task.rb', line 36

def results
  result_set.results
end

#runObject

Raises:



40
41
42
43
44
45
46
# File 'lib/choria/orchestrator/task.rb', line 40

def run
  raise Error, 'Unable to run a task by ID' if name.nil?

  @pending_targets = rpc_client.discover
  _download
  _run_no_wait
end

#waitObject

Raises:



48
49
50
51
52
53
54
55
56
57
# File 'lib/choria/orchestrator/task.rb', line 48

def wait
  raise Error, 'Task ID is required!' if @id.nil?

  logger.info "Waiting task #{@id} results…"
  @rpc_results = []
  loop do
    self.rpc_results = rpc_client.task_status(task_id: @id).map(&:results)
    break if @pending_targets.empty?
  end
end