Class: Choria::Orchestrator::Task
- Inherits:
-
Object
- Object
- Choria::Orchestrator::Task
- 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
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#input ⇒ Object
readonly
Returns the value of attribute input.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #files ⇒ Object
-
#initialize(orchestrator:, id: nil, name: nil, input: {}, environment: 'production') ⇒ Task
constructor
A new instance of Task.
- #metadata ⇒ Object
- #on_result(&block) ⇒ Object
- #results ⇒ Object
- #run ⇒ Object
- #wait ⇒ Object
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
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
14 15 16 |
# File 'lib/choria/orchestrator/task.rb', line 14 def environment @environment end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
14 15 16 |
# File 'lib/choria/orchestrator/task.rb', line 14 def id @id end |
#input ⇒ Object (readonly)
Returns the value of attribute input.
14 15 16 |
# File 'lib/choria/orchestrator/task.rb', line 14 def input @input end |
#name ⇒ Object (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
#files ⇒ Object
32 33 34 |
# File 'lib/choria/orchestrator/task.rb', line 32 def files ['files'].to_json end |
#metadata ⇒ Object
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 |
#results ⇒ Object
36 37 38 |
# File 'lib/choria/orchestrator/task.rb', line 36 def results result_set.results end |
#run ⇒ Object
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 |
#wait ⇒ Object
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 |