Class: VcoWorkflows::WorkflowToken

Inherits:
Object
  • Object
show all
Defined in:
lib/vcoworkflows/workflowtoken.rb

Overview

WorkflowToken is used for workflow execution results, and contains as much data on the given workflow execution instance as vCO can provide.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(workflow_service, workflow_id, execution_id) ⇒ VcoWorkflows::WorkflowToken

Create a new workflow token

Parameters:

  • workflow_service (VcoWorkflows::WorkflowService)

    Workflow service to use

  • workflow_id (String)

    GUID of the workflow

  • execution_id (String)

    GUID of execution



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
105
106
107
108
109
# 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)

  # rubocop:disable SpaceAroundOperators
  @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
  # rubocop:enable SpaceAroundOperators

  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

Instance Attribute Details

#content_exceptionString (readonly)

Returns:

  • (String)


51
52
53
# File 'lib/vcoworkflows/workflowtoken.rb', line 51

def content_exception
  @content_exception
end

#current_item_nameString (readonly)

Returns:

  • (String)


45
46
47
# File 'lib/vcoworkflows/workflowtoken.rb', line 45

def current_item_name
  @current_item_name
end

#current_item_stateString (readonly)

Returns:

  • (String)


48
49
50
# File 'lib/vcoworkflows/workflowtoken.rb', line 48

def current_item_state
  @current_item_state
end

#end_dateString (readonly)

Execution end date

Returns:

  • (String)

    date and time the workflow execution ended



38
39
40
# File 'lib/vcoworkflows/workflowtoken.rb', line 38

def end_date
  @end_date
end

#global_stateString (readonly)

Returns:

  • (String)


54
55
56
# File 'lib/vcoworkflows/workflowtoken.rb', line 54

def global_state
  @global_state
end

#hrefString (readonly)

Execution href

Returns:

  • (String)

    link to this execution via the REST API



30
31
32
# File 'lib/vcoworkflows/workflowtoken.rb', line 30

def href
  @href
end

#idString (readonly)

Workflow execution ID

Returns:

  • (String)

    the execution id for this token



14
15
16
# File 'lib/vcoworkflows/workflowtoken.rb', line 14

def id
  @id
end

#input_parametersVcoWorkflows::WorkflowParameter{} (readonly)

Workflow execution input parameters

Returns:



58
59
60
# File 'lib/vcoworkflows/workflowtoken.rb', line 58

def input_parameters
  @input_parameters
end

#json_contentString (readonly)

Source JSON

Returns:

  • (String)

    source JSON document returned by vCO for this execution



66
67
68
# File 'lib/vcoworkflows/workflowtoken.rb', line 66

def json_content
  @json_content
end

#nameString (readonly)

Workflow name

Returns:

  • (String)

    name of the workflow



22
23
24
# File 'lib/vcoworkflows/workflowtoken.rb', line 22

def name
  @name
end

#output_parametersVcoWorkflows::WorkflowParameter{} (readonly)

Workflow execution output parameters

Returns:



62
63
64
# File 'lib/vcoworkflows/workflowtoken.rb', line 62

def output_parameters
  @output_parameters
end

#start_dateString (readonly)

Execution start date

Returns:

  • (String)

    date and time the workflow execution started



34
35
36
# File 'lib/vcoworkflows/workflowtoken.rb', line 34

def start_date
  @start_date
end

#started_byString (readonly)

Execution started by

Returns:

  • (String)

    vCO user who started this execution



42
43
44
# File 'lib/vcoworkflows/workflowtoken.rb', line 42

def started_by
  @started_by
end

#stateString (readonly)

Execution state

Returns:

  • (String)

    current state of the workflow execution



26
27
28
# File 'lib/vcoworkflows/workflowtoken.rb', line 26

def state
  @state
end

#workflow_idString (readonly)

Workflow ID

Returns:

  • (String)

    the GUID for this workflow



18
19
20
# File 'lib/vcoworkflows/workflowtoken.rb', line 18

def workflow_id
  @workflow_id
end

Instance Method Details

#alive?Boolean

Is the workflow execution still alive?

Returns:

  • (Boolean)


114
115
116
# File 'lib/vcoworkflows/workflowtoken.rb', line 114

def alive?
  running? || waiting?
end

#running?Boolean

Is the workflow actively running?

Returns:

  • (Boolean)


120
121
122
# File 'lib/vcoworkflows/workflowtoken.rb', line 120

def running?
  state.eql?('running')
end

#to_jsonString

Convert this object to a JSON document (string)

Returns:

  • (String)

    JSON representation of the workflow token



153
154
155
# File 'lib/vcoworkflows/workflowtoken.rb', line 153

def to_json
  JSON.pretty_generate(JSON.parse(@json_content))
end

#to_sString

Convert this object to a string representation

Returns:

  • (String)


134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/vcoworkflows/workflowtoken.rb', line 134

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? } if @input_parameters.size > 0
  string << "\nOutput Parameters:" << "\n"
  @output_parameters.each_value { |wf_param| string << " #{wf_param}" } if @output_parameters.size > 0
  string
end

#waiting?Boolean

Is the workflow in a waiting state?

Returns:

  • (Boolean)


126
127
128
# File 'lib/vcoworkflows/workflowtoken.rb', line 126

def waiting?
  state.match(/waiting/).nil? ? false : true
end