Class: Choria::Colt

Inherits:
Object
  • Object
show all
Defined in:
lib/choria/colt.rb,
lib/choria/colt/cli.rb,
lib/choria/colt/version.rb,
lib/choria/colt/cli/thor.rb,
lib/choria/colt/debugger.rb,
lib/choria/colt/cli/formatter.rb,
lib/choria/colt/data_structurer.rb

Defined Under Namespace

Modules: DataStructurer, Debugger Classes: CLI, Error, Thor

Constant Summary collapse

VERSION =
'0.8.0'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logger: nil) ⇒ Colt

Returns a new instance of Colt.



17
18
19
20
21
# File 'lib/choria/colt.rb', line 17

def initialize(logger: nil)
  @logger = logger

  @orchestrator = Choria::Orchestrator.new logger: @logger
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



15
16
17
# File 'lib/choria/colt.rb', line 15

def logger
  @logger
end

#orchestratorObject (readonly)

Returns the value of attribute orchestrator.



15
16
17
# File 'lib/choria/colt.rb', line 15

def orchestrator
  @orchestrator
end

Instance Method Details

#run_bolt_task(task_name, input: {}, targets: nil, targets_with_classes: nil, environment: 'production', &block) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/choria/colt.rb', line 23

def run_bolt_task(task_name, input: {}, targets: nil, targets_with_classes: nil, environment: 'production', &block)
  logger.debug "Instantiate task '#{task_name}' and validate input"
  task = Choria::Orchestrator::Task.new(name: task_name, input: input, environment: environment, orchestrator: orchestrator)

  task.on_result(&block) if block_given?

  orchestrator.run(task, targets: targets, targets_with_classes: targets_with_classes)
  task.wait
  task.results
rescue Choria::Orchestrator::Error => e
  logger.error e.message
  raise
end

#tasks(environment:, cache: nil, force_cache_refresh: false) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/choria/colt.rb', line 49

def tasks(environment:, cache: nil, force_cache_refresh: false)
  cache ||= ActiveSupport::Cache::MemoryStore.new

  tasks_names = orchestrator.tasks_support.tasks(environment).map do |task|
    task['name']
  end

  tasks_names.map do |task_name|
     = cache.fetch(task_name, force: force_cache_refresh) do
      (task_name, environment)
    end
    [task_name, ]
  end.to_h
end

#wait_bolt_task(task_id, targets: nil, targets_with_classes: nil, &block) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/choria/colt.rb', line 37

def wait_bolt_task(task_id, targets: nil, targets_with_classes: nil, &block)
  orchestrator.discover(targets: targets, targets_with_classes: targets_with_classes)

  task = Choria::Orchestrator::Task.new(id: task_id, orchestrator: orchestrator)
  task.on_result(&block) if block_given?
  task.wait
  task.results
rescue Choria::Orchestrator::Error => e
  logger.error e.message
  raise
end