Class: VcoWorkflows::Cli::Execute

Inherits:
Thor::Group
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/vcoworkflows/cli/execute.rb

Overview

Execute a workflow with the given options.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootObject

Thor



27
28
29
# File 'lib/vcoworkflows/cli/execute.rb', line 27

def self.source_root
  File.dirname(__FILE__)
end

Instance Method Details

#executeObject

rubocop:disable CyclomaticComplexity, PerceivedComplexity



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/vcoworkflows/cli/execute.rb', line 32

def execute
  config = VcoWorkflows::Config.new(url:        options[:server],
                                    username:   options[:username],
                                    password:   options[:password],
                                    verify_ssl: options[:verify_ssl])

  # Parse out the parameters
  parameters = {}
  options[:parameters].split(/,/).each do |p|
    k, v = p.split(/=/)
    parameters[k] = v
  end
  if parameters.key?('runlist')
    parameters['runlist'] = parameters['runlist'].split(/:/)
  end

  puts "Executing against vCO REST endpoint: #{options[:server]}"
  puts "Requested execution of workflow: '#{workflow}'"
  puts "Will call workflow by GUID (#{options[:id]})" if options[:id]
  if options[:verbose] || options[:dry_run]
    puts 'Parameters:'
    parameters.each do |k, v|
      v = v.join(',') if v.is_a?(Array)
      puts " - #{k}: #{v}"
    end
    puts ''
  end

  return if options[:dry_run]

  # Get the workflow
  puts "Retrieving workflow '#{workflow}' ..."
  wf = VcoWorkflows::Workflow.new(workflow,
                                  id:     options[:id],
                                  config: config)

  # List out mandatory parameters
  puts "Required parameters:\n #{wf.required_parameters.keys.join(', ')}"

  # Set the input parameters
  puts 'Setting workflow input parameters...' if options[:verbose]
  parameters.each do |k, v|
    puts "setting #{k} to #{v}" if options[:verbose]
    wf.set_parameter(k, v)
  end

  # Execute the workflow
  puts 'Executing workflow...'
  wf.execute

  # Fetch the results
  wftoken = wf.token
  puts "#{wftoken.id} started at #{Time.at(wftoken.start_date / 1000)}"

  # If we don't care about the results, move on.
  return unless options[:watch]

  # Check for update results until we get one who's state
  # is not "running" or "waiting"
  puts "\nChecking status...\n"
  while wftoken.alive?
    sleep 10
    wftoken = wf.token
    puts "#{Time.now} state: #{wftoken.state}"
  end
  puts "\nFinal status of execution:"
  puts wftoken

  # Print out the execution log
  puts "\nWorkflow #{wf.name} log for execution #{wftoken.id}:"
  log = wf.log(wftoken.id)
  puts "\n#{log}"
end