Class: Proxy::OpenBolt::TaskJob

Inherits:
Job
  • Object
show all
Defined in:
lib/smart_proxy_openbolt/task_job.rb

Instance Attribute Summary collapse

Attributes inherited from Job

#id, #name, #options, #parameters, #status

Instance Method Summary collapse

Methods inherited from Job

#process, #result, #store_result, #update_status

Constructor Details

#initialize(name, parameters, options, targets) ⇒ TaskJob

NOTE: Validation of all objects initialized here should be done in main.rb BEFORE creating this object.



12
13
14
15
# File 'lib/smart_proxy_openbolt/task_job.rb', line 12

def initialize(name, parameters, options, targets)
  super(name, parameters, options)
  @targets = targets
end

Instance Attribute Details

#targetsObject (readonly)

Returns the value of attribute targets.



8
9
10
# File 'lib/smart_proxy_openbolt/task_job.rb', line 8

def targets
  @targets
end

Instance Method Details

#executeObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/smart_proxy_openbolt/task_job.rb', line 17

def execute
  command = ['bolt', 'task', 'run', @name,
             '--targets', @targets.join(','),
             '--no-save-rerun',
             "--concurrency=#{Plugin.settings.concurrency}",
             "--connect-timeout=#{Plugin.settings.connect_timeout}",
             '--project', Plugin.settings.environment_path,
             '--format', 'json',
             '--no-color']
  command.concat(parse_options)
  command.concat(parse_parameters)
  stdout, stderr, exitcode = Proxy::OpenBolt.openbolt(command)
  Result.new(
    Proxy::OpenBolt.scrub(@options, command.join(' ')),
    Proxy::OpenBolt.scrub(@options, stdout),
    Proxy::OpenBolt.scrub(@options, stderr),
    exitcode
  )
end

#parse_optionsObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/smart_proxy_openbolt/task_job.rb', line 44

def parse_options
  opts = []
  return opts unless @options

  @options.each do |key, value|
    # --noop doesn't have a --[no-] prefix
    next if key == 'noop' && value.is_a?(FalseClass)
    # For some mindboggling reason, there are both '--log-level trace'
    # and '--trace' options. We only expose log level, so just
    # tack on --trace if that's what we find.
    if key == 'log-level' && value == 'trace'
      opts << '--log-level=trace'
      opts << '--trace'
    elsif value.is_a?(TrueClass)
      opts << "--#{key}"
    elsif value.is_a?(FalseClass)
      opts << "--no-#{key}"
    else
      opts << "--#{key}=#{value}"
    end
  end
  opts
end

#parse_parametersObject



37
38
39
40
41
42
# File 'lib/smart_proxy_openbolt/task_job.rb', line 37

def parse_parameters
  @parameters.map do |key, value|
    formatted = value.is_a?(Array) || value.is_a?(Hash) ? value.to_json : value
    "#{key}=#{formatted}"
  end
end