simplerubysteps 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/bin/setup +0 -1
- data/exe/simplerubysteps-deploy +1 -1
- data/exe/simplerubysteps-destroy +1 -1
- data/exe/simplerubysteps-logs +6 -0
- data/exe/simplerubysteps-workflow-run +1 -1
- data/lib/function.rb +11 -6
- data/lib/logs.sh +7 -0
- data/lib/simplerubysteps/version.rb +1 -1
- data/lib/simplerubysteps.rb +169 -129
- data/samples/sample1/continue-callbackbranch.sh +5 -0
- data/samples/sample1/send-task-success.sh +6 -0
- data/samples/sample1/start-callbackbranch.sh +3 -0
- data/samples/sample1/start-directbranch.sh +3 -0
- data/samples/sample1/workflow.rb +25 -25
- data/simplerubysteps.gemspec +12 -20
- metadata +9 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8be19b6aa108f0bad7ca85714f134b3ae8876a43a2da627f685fc1f181a1e81b
|
4
|
+
data.tar.gz: feb25d925cc950177873b1e6a5a2bf19406d7b7a796ee0983d03a44461d49d6c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '04878fef3099b7798994503ceb9c373d559a0bee170ac9747b26a4f27548cd978810627c08ffe579a05eaf0e2bec1ab6d82e7288852c07cec9438b9403181ec4'
|
7
|
+
data.tar.gz: 6c719c0cc7ae0e8a9e25387131f552ece86774eed9b45649589070d3e32f1f593e6bcac3915dca64ec836d0cdce647868b2b6a1f6d73c1e6f6efecc2379eadad
|
data/README.md
CHANGED
data/bin/setup
CHANGED
data/exe/simplerubysteps-deploy
CHANGED
data/exe/simplerubysteps-destroy
CHANGED
data/lib/function.rb
CHANGED
@@ -1,9 +1,14 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "json"
|
2
|
+
require "./workflow.rb"
|
3
3
|
|
4
4
|
def handler(event:, context:)
|
5
|
-
puts ENV.inspect
|
6
|
-
puts event
|
7
|
-
puts context.inspect
|
8
|
-
|
5
|
+
puts ENV.inspect # FIXME remove DEBUG code
|
6
|
+
puts event # FIXME remove DEBUG code
|
7
|
+
puts context.inspect # FIXME remove DEBUG code
|
8
|
+
|
9
|
+
if event["Token"]
|
10
|
+
$sm.states[event["Task"].to_sym].perform_action event["Input"], event["Token"]
|
11
|
+
else
|
12
|
+
$sm.states[event["Task"].to_sym].perform_action event["Input"]
|
13
|
+
end
|
9
14
|
end
|
data/lib/logs.sh
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
export STACK_NAME=$(basename "$PWD")
|
4
|
+
|
5
|
+
export FUNCTION_NAME=$(aws cloudformation describe-stacks --stack-name $STACK_NAME --output text --query "Stacks[].Outputs[]"|grep LambdaFunctionName|awk '{print $2}')
|
6
|
+
|
7
|
+
aws logs tail /aws/lambda/$FUNCTION_NAME
|
data/lib/simplerubysteps.rb
CHANGED
@@ -2,177 +2,217 @@ require "simplerubysteps/version"
|
|
2
2
|
require "json"
|
3
3
|
|
4
4
|
module Simplerubysteps
|
5
|
-
|
5
|
+
# Step Functions JSON generator
|
6
|
+
|
7
|
+
$FUNCTION_ARN = ENV["LAMBDA_FUNCTION_ARN"] ? ENV["LAMBDA_FUNCTION_ARN"] : "unknown"
|
8
|
+
|
9
|
+
def function_name
|
10
|
+
return "unknown" unless $FUNCTION_ARN =~ /.+\:function\:(.+)/
|
11
|
+
$1
|
12
|
+
end
|
6
13
|
|
7
14
|
class StateMachine
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
15
|
+
attr_reader :states
|
16
|
+
attr_reader :start_at
|
17
|
+
|
18
|
+
def initialize()
|
19
|
+
@states = {}
|
20
|
+
end
|
21
|
+
|
22
|
+
def add(state)
|
23
|
+
@start_at = state.name unless @start_at
|
24
|
+
|
25
|
+
@states[state.name] = state
|
26
|
+
state.state_machine = self
|
27
|
+
|
28
|
+
state
|
29
|
+
end
|
30
|
+
|
31
|
+
def render
|
32
|
+
{
|
33
|
+
:StartAt => @start_at,
|
34
|
+
:States => @states.map { |name, state| [name, state.render] }.to_h,
|
35
|
+
}
|
36
|
+
end
|
30
37
|
end
|
31
38
|
|
32
39
|
class State
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
40
|
+
attr_reader :name
|
41
|
+
attr_accessor :state_machine
|
42
|
+
|
43
|
+
def initialize(name)
|
44
|
+
@name = name
|
45
|
+
@dict = {}
|
46
|
+
end
|
47
|
+
|
48
|
+
def []=(key, value)
|
49
|
+
@dict[key] = value
|
50
|
+
end
|
51
|
+
|
52
|
+
def next=(state)
|
53
|
+
@dict[:Next] = (state.is_a? Symbol) ? state : state.name
|
54
|
+
end
|
55
|
+
|
56
|
+
def render
|
57
|
+
dict = @dict
|
58
|
+
dict[:End] = true unless dict[:Next]
|
59
|
+
dict
|
60
|
+
end
|
54
61
|
end
|
55
62
|
|
56
63
|
class Task < State
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
64
|
+
def initialize(name)
|
65
|
+
super
|
66
|
+
@dict[:Type] = "Task"
|
67
|
+
@dict[:Resource] = $FUNCTION_ARN
|
68
|
+
@dict[:Parameters] = {
|
69
|
+
:Task => name,
|
70
|
+
"Input.$" => "$",
|
71
|
+
}
|
72
|
+
end
|
73
|
+
|
74
|
+
def action(&action_block)
|
75
|
+
@action_block = action_block
|
76
|
+
end
|
77
|
+
|
78
|
+
def perform_action(input)
|
79
|
+
@action_block.call(input) if @action_block
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
class Callback < State
|
84
|
+
def initialize(name)
|
85
|
+
super
|
86
|
+
@dict[:Type] = "Task"
|
87
|
+
@dict[:Resource] = "arn:aws:states:::lambda:invoke.waitForTaskToken"
|
88
|
+
@dict[:Parameters] = {
|
89
|
+
:FunctionName => function_name,
|
90
|
+
:Payload => {
|
91
|
+
:Task => name,
|
92
|
+
"Input.$" => "$",
|
93
|
+
"Token.$" => "$$.Task.Token",
|
94
|
+
},
|
95
|
+
}
|
96
|
+
end
|
97
|
+
|
98
|
+
def action(&action_block)
|
99
|
+
@action_block = action_block
|
100
|
+
end
|
101
|
+
|
102
|
+
def perform_action(input, token)
|
103
|
+
@action_block.call(input, token) if @action_block
|
104
|
+
end
|
74
105
|
end
|
75
106
|
|
76
|
-
class ChoiceItem
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
107
|
+
class ChoiceItem
|
108
|
+
def initialize(dict = {}, state = nil)
|
109
|
+
@dict = dict
|
110
|
+
self.next = state if state
|
111
|
+
end
|
81
112
|
|
82
|
-
|
83
|
-
|
84
|
-
|
113
|
+
def next=(state)
|
114
|
+
@dict[:Next] = (state.is_a? Symbol) ? state : state.name
|
115
|
+
end
|
85
116
|
|
86
|
-
|
87
|
-
|
88
|
-
|
117
|
+
def render
|
118
|
+
@dict
|
119
|
+
end
|
89
120
|
end
|
90
121
|
|
91
122
|
class Choice < State
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
123
|
+
attr_reader :choices
|
124
|
+
|
125
|
+
def initialize(name)
|
126
|
+
super
|
127
|
+
@choices = []
|
128
|
+
@dict[:Type] = "Choice"
|
129
|
+
end
|
130
|
+
|
131
|
+
def add(item)
|
132
|
+
@choices.push item
|
133
|
+
end
|
134
|
+
|
135
|
+
def add_string_matches(var, match, state)
|
136
|
+
add ChoiceItem.new({
|
137
|
+
:Variable => var,
|
138
|
+
:StringMatches => match,
|
139
|
+
}, state)
|
140
|
+
end
|
141
|
+
|
142
|
+
def default=(state)
|
143
|
+
@dict[:Default] = (state.is_a? Symbol) ? state : state.name
|
144
|
+
end
|
145
|
+
|
146
|
+
def next=(state)
|
147
|
+
self.default = state
|
148
|
+
end
|
149
|
+
|
150
|
+
def render
|
151
|
+
dict = @dict.clone
|
152
|
+
dict[:Choices] = @choices.map { |item| item.render }
|
153
|
+
dict
|
154
|
+
end
|
124
155
|
end
|
125
156
|
|
126
|
-
|
157
|
+
# Workflow DSL
|
127
158
|
|
128
159
|
$sm = StateMachine.new
|
129
160
|
$tasks = []
|
130
161
|
|
131
162
|
def task(name)
|
132
|
-
|
163
|
+
t = $sm.add Task.new(name)
|
133
164
|
|
134
|
-
|
165
|
+
$tasks.last.next = t if $tasks.last
|
135
166
|
|
136
|
-
|
137
|
-
|
138
|
-
|
167
|
+
$tasks.push t
|
168
|
+
yield if block_given?
|
169
|
+
$tasks.pop
|
139
170
|
end
|
140
171
|
|
172
|
+
def callback(name)
|
173
|
+
t = $sm.add Callback.new(name)
|
174
|
+
|
175
|
+
$tasks.last.next = t if $tasks.last
|
176
|
+
|
177
|
+
$tasks.push t
|
178
|
+
yield if block_given?
|
179
|
+
$tasks.pop
|
180
|
+
end
|
141
181
|
|
142
182
|
def action(&action_block)
|
143
|
-
|
183
|
+
$tasks.last.action &action_block
|
144
184
|
end
|
145
185
|
|
146
186
|
def transition(state)
|
147
|
-
|
187
|
+
$tasks.last.next = state
|
148
188
|
end
|
149
189
|
|
150
190
|
def choice(name)
|
151
|
-
|
152
|
-
|
153
|
-
|
191
|
+
t = $sm.add Choice.new(name)
|
192
|
+
|
193
|
+
$tasks.last.next = t if $tasks.last
|
154
194
|
|
155
|
-
|
156
|
-
|
157
|
-
|
195
|
+
$tasks.push t
|
196
|
+
yield if block_given?
|
197
|
+
$tasks.pop
|
158
198
|
end
|
159
199
|
|
160
200
|
def string_matches(var, match)
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
201
|
+
c = ChoiceItem.new({
|
202
|
+
:Variable => var,
|
203
|
+
:StringMatches => match,
|
204
|
+
})
|
165
205
|
|
166
|
-
|
206
|
+
$tasks.last.add c
|
167
207
|
|
168
|
-
|
169
|
-
|
170
|
-
|
208
|
+
$tasks.push c
|
209
|
+
yield if block_given?
|
210
|
+
$tasks.pop
|
171
211
|
end
|
172
212
|
|
173
213
|
def default
|
174
|
-
|
175
|
-
|
176
|
-
|
214
|
+
$tasks.push $tasks.last
|
215
|
+
yield if block_given?
|
216
|
+
$tasks.pop
|
177
217
|
end
|
178
218
|
end
|
data/samples/sample1/workflow.rb
CHANGED
@@ -4,37 +4,37 @@ require "simplerubysteps"
|
|
4
4
|
include Simplerubysteps
|
5
5
|
|
6
6
|
task :t1 do
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
choice :t2 do
|
13
|
-
string_matches "$.Foo1", "ja" do
|
14
|
-
task :t3 do
|
15
|
-
action do |input|
|
16
|
-
puts "Task t3: #{input}"
|
17
|
-
input.merge({ "Foo3": "Bar3x" })
|
18
|
-
end
|
7
|
+
action do |input|
|
8
|
+
puts "Task t1: #{input}"
|
9
|
+
input.merge({ "Foo1" => (input["foo"] == "John Wick" ? "ja" : "nein") })
|
10
|
+
end
|
19
11
|
|
20
|
-
|
21
|
-
|
12
|
+
choice :t2 do
|
13
|
+
string_matches "$.Foo1", "ja" do
|
14
|
+
callback :t3 do
|
15
|
+
action do |input, token|
|
16
|
+
puts "Callback t3: #{input}, #{token}"
|
17
|
+
# input.merge({ "Foo3": "Bar3x" })
|
22
18
|
end
|
23
19
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
20
|
+
transition :t5
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
default do
|
25
|
+
task :t4 do
|
26
|
+
action do |input|
|
27
|
+
puts "Task t4: #{input}"
|
28
|
+
input.merge({ "Foo4": "Bar4xy" })
|
31
29
|
end
|
30
|
+
end
|
32
31
|
end
|
32
|
+
end
|
33
33
|
end
|
34
34
|
|
35
35
|
task :t5 do
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
36
|
+
action do |input|
|
37
|
+
puts "Task t5: #{input}"
|
38
|
+
input.merge({ "Foo5" => "Bar5" })
|
39
|
+
end
|
40
40
|
end
|
data/simplerubysteps.gemspec
CHANGED
@@ -3,31 +3,23 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
3
|
require "simplerubysteps/version"
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
|
-
spec.name
|
7
|
-
spec.version
|
8
|
-
spec.authors
|
9
|
-
spec.email
|
6
|
+
spec.name = "simplerubysteps"
|
7
|
+
spec.version = Simplerubysteps::VERSION
|
8
|
+
spec.authors = ["Christian Tschenett"]
|
9
|
+
spec.email = ["simplerubysteps@furthermore.ch"]
|
10
10
|
|
11
|
-
spec.summary
|
12
|
-
|
13
|
-
spec.homepage = "https://github.com/chtz/simplerubysteps"
|
14
|
-
spec.license = "MIT"
|
11
|
+
spec.summary = %q{simplerubysteps makes it easy to manage AWS Step Functions with ruby (eventually - this is an early alpha version and should not really be used by everyone).}
|
15
12
|
|
16
|
-
spec.
|
13
|
+
spec.homepage = "https://github.com/chtz/simplerubysteps"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
|
17
17
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
18
|
end
|
19
|
-
spec.files << "lib/deploy.sh"
|
20
|
-
spec.files << "lib/destroy.sh"
|
21
|
-
spec.files << "lib/workflow-run.sh"
|
22
|
-
spec.files << "lib/statemachine.yaml"
|
23
|
-
spec.files << "lib/function.rb"
|
24
19
|
|
25
|
-
spec.bindir
|
26
|
-
spec.executables
|
27
|
-
|
28
|
-
spec.executables << "simplerubysteps-destroy"
|
29
|
-
spec.executables << "simplerubysteps-workflow-run"
|
30
|
-
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
|
31
23
|
spec.require_paths = ["lib"]
|
32
24
|
|
33
25
|
spec.add_development_dependency "bundler", "~> 1.17"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simplerubysteps
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christian Tschenett
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-04-
|
11
|
+
date: 2023-04-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -44,6 +44,7 @@ email:
|
|
44
44
|
executables:
|
45
45
|
- simplerubysteps-deploy
|
46
46
|
- simplerubysteps-destroy
|
47
|
+
- simplerubysteps-logs
|
47
48
|
- simplerubysteps-workflow-run
|
48
49
|
extensions: []
|
49
50
|
extra_rdoc_files: []
|
@@ -57,14 +58,20 @@ files:
|
|
57
58
|
- bin/setup
|
58
59
|
- exe/simplerubysteps-deploy
|
59
60
|
- exe/simplerubysteps-destroy
|
61
|
+
- exe/simplerubysteps-logs
|
60
62
|
- exe/simplerubysteps-workflow-run
|
61
63
|
- lib/deploy.sh
|
62
64
|
- lib/destroy.sh
|
63
65
|
- lib/function.rb
|
66
|
+
- lib/logs.sh
|
64
67
|
- lib/simplerubysteps.rb
|
65
68
|
- lib/simplerubysteps/version.rb
|
66
69
|
- lib/statemachine.yaml
|
67
70
|
- lib/workflow-run.sh
|
71
|
+
- samples/sample1/continue-callbackbranch.sh
|
72
|
+
- samples/sample1/send-task-success.sh
|
73
|
+
- samples/sample1/start-callbackbranch.sh
|
74
|
+
- samples/sample1/start-directbranch.sh
|
68
75
|
- samples/sample1/workflow.rb
|
69
76
|
- simplerubysteps.gemspec
|
70
77
|
homepage: https://github.com/chtz/simplerubysteps
|