Class: Floe::Workflow::Context
- Inherits:
-
Object
- Object
- Floe::Workflow::Context
show all
- Includes:
- Logging
- Defined in:
- lib/floe/workflow/context.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Logging
included, #logger, #logger=
Constructor Details
#initialize(context = nil, input: nil, credentials: {}, logger: nil) ⇒ Context
Returns a new instance of Context.
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/floe/workflow/context.rb', line 12
def initialize(context = nil, input: nil, credentials: {}, logger: nil)
context = JSON.parse(context) if context.kind_of?(String)
input = JSON.parse(input || "{}")
@context = context || {}
self["Execution"] ||= {}
self["Execution"]["Input"] ||= input
self["State"] ||= {}
self["StateHistory"] ||= []
self["StateMachine"] ||= {}
self["Task"] ||= {}
@credentials = credentials || {}
self.logger = logger if logger
rescue JSON::ParserError => err
raise Floe::InvalidExecutionInput, "Invalid State Machine Execution Input: #{err}: was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')"
end
|
Instance Attribute Details
#credentials ⇒ Object
Returns the value of attribute credentials.
8
9
10
|
# File 'lib/floe/workflow/context.rb', line 8
def credentials
@credentials
end
|
Instance Method Details
#[](key) ⇒ Object
129
130
131
|
# File 'lib/floe/workflow/context.rb', line 129
def [](key)
@context[key]
end
|
#[]=(key, val) ⇒ Object
133
134
135
|
# File 'lib/floe/workflow/context.rb', line 133
def []=(key, val)
@context[key] = val
end
|
#dig(*args) ⇒ Object
137
138
139
|
# File 'lib/floe/workflow/context.rb', line 137
def dig(*args)
@context.dig(*args)
end
|
#ended? ⇒ Boolean
47
48
49
|
# File 'lib/floe/workflow/context.rb', line 47
def ended?
execution.key?("EndTime")
end
|
#execution ⇒ Object
31
32
33
|
# File 'lib/floe/workflow/context.rb', line 31
def execution
@context["Execution"]
end
|
#failed? ⇒ Boolean
43
44
45
|
# File 'lib/floe/workflow/context.rb', line 43
def failed?
(output.kind_of?(Hash) && output.key?("Error")) || false
end
|
55
56
57
|
# File 'lib/floe/workflow/context.rb', line 55
def input
state["Input"]
end
|
59
60
61
|
# File 'lib/floe/workflow/context.rb', line 59
def json_input
input.to_json
end
|
#json_output ⇒ Object
67
68
69
|
# File 'lib/floe/workflow/context.rb', line 67
def json_output
output.to_json
end
|
#next_state ⇒ Object
79
80
81
|
# File 'lib/floe/workflow/context.rb', line 79
def next_state
state["NextState"]
end
|
#next_state=(val) ⇒ Object
83
84
85
|
# File 'lib/floe/workflow/context.rb', line 83
def next_state=(val)
state["NextState"] = val
end
|
#output ⇒ Object
63
64
65
|
# File 'lib/floe/workflow/context.rb', line 63
def output
state["Output"]
end
|
#output=(val) ⇒ Object
71
72
73
|
# File 'lib/floe/workflow/context.rb', line 71
def output=(val)
state["Output"] = val
end
|
#running? ⇒ Boolean
39
40
41
|
# File 'lib/floe/workflow/context.rb', line 39
def running?
started? && !ended?
end
|
#started? ⇒ Boolean
35
36
37
|
# File 'lib/floe/workflow/context.rb', line 35
def started?
execution.key?("StartTime")
end
|
#state ⇒ Object
51
52
53
|
# File 'lib/floe/workflow/context.rb', line 51
def state
@context["State"]
end
|
#state=(val) ⇒ Object
113
114
115
|
# File 'lib/floe/workflow/context.rb', line 113
def state=(val)
@context["State"] = val
end
|
#state_finished? ⇒ Boolean
State#running? also checks docker to see if it is running. You possibly want to use that instead
109
110
111
|
# File 'lib/floe/workflow/context.rb', line 109
def state_finished?
state.key?("FinishedTime")
end
|
#state_history ⇒ Object
117
118
119
|
# File 'lib/floe/workflow/context.rb', line 117
def state_history
@context["StateHistory"]
end
|
#state_machine ⇒ Object
121
122
123
|
# File 'lib/floe/workflow/context.rb', line 121
def state_machine
@context["StateMachine"]
end
|
#state_name ⇒ Object
75
76
77
|
# File 'lib/floe/workflow/context.rb', line 75
def state_name
state["Name"]
end
|
#state_started? ⇒ Boolean
103
104
105
|
# File 'lib/floe/workflow/context.rb', line 103
def state_started?
state.key?("EnteredTime")
end
|
#status ⇒ Object
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/floe/workflow/context.rb', line 87
def status
if !started?
"pending"
elsif running?
"running"
elsif failed?
"failure"
else
"success"
end
end
|
#success? ⇒ Boolean
99
100
101
|
# File 'lib/floe/workflow/context.rb', line 99
def success?
status == "success"
end
|
#task ⇒ Object
125
126
127
|
# File 'lib/floe/workflow/context.rb', line 125
def task
@context["Task"]
end
|
#to_h ⇒ Object
141
142
143
|
# File 'lib/floe/workflow/context.rb', line 141
def to_h
@context
end
|