class VcoWorkflows::WorkflowToken
WorkflowToken
is used for workflow execution results, and contains as much data on the given workflow execution instance as vCO can provide.
Attributes
@return [String]
@return [String]
@return [String]
Execution end date @return [String] date and time the workflow execution ended
@return [String]
Execution href @return [String] link to this execution via the REST API
Workflow
execution ID @return [String] the execution id for this token
Workflow
execution input parameters @return [VcoWorkflows::WorkflowParameter{}] Hash of input parameters which were given when the workflow was executed
Source JSON @return [String] source JSON document returned by vCO for this execution
Workflow
name @return [String] name of the workflow
Workflow
execution output parameters @return [VcoWorkflows::WorkflowParameter{}] Hash of output parameters set by the workflow execution
Execution start date @return [String] date and time the workflow execution started
Execution started by @return [String] vCO user who started this execution
Execution state @return [String] current state of the workflow execution
Workflow
ID @return [String] the GUID for this workflow
Public Class Methods
Create a new workflow token @param [VcoWorkflows::WorkflowService] workflow_service Workflow
service to use @param [String] workflow_id
GUID of the workflow @param [String] execution_id GUID of execution @return [VcoWorkflows::WorkflowToken]
# File lib/vcoworkflows/workflowtoken.rb, line 77 def initialize(workflow_service, workflow_id, execution_id) @service = workflow_service @workflow_id = workflow_id @json_content = @service.get_execution(workflow_id, execution_id) token = JSON.parse(@json_content) @id = token.key?('id') ? token['id'] : nil @name = token.key?('name') ? token['name'] : nil @state = token.key?('state') ? token['state'] : nil @href = token.key?('href') ? token['href'] : nil @start_date = token.key?('start-date') ? token['start-date'] : nil @end_date = token.key?('end-date') ? token['end-date'] : nil @started_by = token.key?('started-by') ? token['started-by'] : nil @current_item_name = token.key?('current-item-display-name') ? token['current-item-display-name'] : nil @current_item_state = token.key?('current-item-state') ? token['current-item-state'] : nil @global_state = token.key?('global-state') ? token['global-state'] : nil @content_exception = token.key?('content-exeption') ? token['content-exception'] : nil if token.key?('input-parameters') @input_parameters = VcoWorkflows::Workflow.parse_parameters(token['input-parameters']) else @input_parameters = {} end if token.key?('output-parameters') @output_parameters = VcoWorkflows::Workflow.parse_parameters(token['output-parameters']) else @output_parameters = {} end end
Public Instance Methods
Is the workflow execution still alive? @return [Boolean]
# File lib/vcoworkflows/workflowtoken.rb, line 111 def alive? running? || waiting? end
Is the workflow actively running? @return [Boolean]
# File lib/vcoworkflows/workflowtoken.rb, line 117 def running? state.eql?('running') end
Convert this object to a JSON document (string) @return [String] JSON representation of the workflow token
# File lib/vcoworkflows/workflowtoken.rb, line 150 def to_json JSON.pretty_generate(JSON.parse(@json_content)) end
Convert this object to a string representation @return [String]
# File lib/vcoworkflows/workflowtoken.rb, line 131 def to_s string = "Execution ID: #{@id}\n" string << "Name: #{@name}\n" string << "Workflow ID: #{@workflow_id}\n" string << "State: #{@state}\n" string << "Start Date: #{Time.at(@start_date / 1000)}\n" string << "End Date: #{end_date.nil? ? '' : Time.at(@end_date / 1000)}\n" string << "Started By: #{@started_by}\n" string << "Content Exception: #{@content_exception}\n" unless @content_exception.nil? string << "\nInput Parameters:\n" @input_parameters.each_value { |wf_param| string << " #{wf_param}" if wf_param.set? } unless @input_parameters.empty? string << "\nOutput Parameters:" << "\n" @output_parameters.each_value { |wf_param| string << " #{wf_param}" } unless @output_parameters.empty? string end
Is the workflow in a waiting state? @return [Boolean]
# File lib/vcoworkflows/workflowtoken.rb, line 123 def waiting? state.match(/waiting/).nil? ? false : true end