class VcoWorkflows::Cli::Execute
Execute
a workflow with the given options.
Public Class Methods
source_root()
click to toggle source
Thor
# File lib/vcoworkflows/cli/execute.rb, line 27 def self.source_root File.dirname(__FILE__) end
Public Instance Methods
execute()
click to toggle source
rubocop:disable CyclomaticComplexity, PerceivedComplexity
# 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