Class: InsightsCloud::Generators::PlaybookProgressGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/insights_cloud/generators/playbook_progress_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(correlation_id) ⇒ PlaybookProgressGenerator

Returns a new instance of PlaybookProgressGenerator.



5
6
7
8
# File 'lib/insights_cloud/generators/playbook_progress_generator.rb', line 5

def initialize(correlation_id)
  @messages = []
  @correlation_id = correlation_id
end

Instance Attribute Details

#correlation_idObject (readonly)

Returns the value of attribute correlation_id.



4
5
6
# File 'lib/insights_cloud/generators/playbook_progress_generator.rb', line 4

def correlation_id
  @correlation_id
end

Instance Method Details

#generateObject



42
43
44
45
46
# File 'lib/insights_cloud/generators/playbook_progress_generator.rb', line 42

def generate
  @messages.map do |message|
    message.to_json
  end.join("\n")
end

#host_finished_message(host_name, exit_code) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/insights_cloud/generators/playbook_progress_generator.rb', line 21

def host_finished_message(host_name, exit_code)
  @messages << {
    "type": "playbook_run_finished",
    "version": 3,
    "correlation_id": correlation_id,
    "host": host_name,
    "status": exit_code == 0 ? 'success' : 'failure',
    "connection_code": 0,
    "execution_code": exit_code,
  }
end

#host_progress_message(host_name, output, sequence) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/insights_cloud/generators/playbook_progress_generator.rb', line 10

def host_progress_message(host_name, output, sequence)
  @messages << {
    "type": "playbook_run_update",
    "version": 3,
    "correlation_id": correlation_id,
    "sequence": sequence,
    "host": host_name,
    "console": output,
  }
end

#job_finished_message(success) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/insights_cloud/generators/playbook_progress_generator.rb', line 33

def job_finished_message(success)
  @messages << {
    "type": "playbook_run_completed",
    "version": 3,
    "correlation_id": correlation_id,
    "status": success ? 'success' : 'failure',
  }
end