simplerubysteps 0.0.3 → 0.0.5
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 +7 -0
- data/exe/simplerubysteps-workflow-run-sync +6 -0
- data/lib/deploy.sh +2 -1
- data/lib/simplerubysteps/version.rb +1 -1
- data/lib/simplerubysteps.rb +57 -1
- data/lib/statemachine.yaml +5 -0
- data/lib/workflow-run-sync.sh +10 -0
- data/samples/sample1/workflow.rb +1 -2
- data/samples/sample2/workflow.rb +42 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1db80d874fc5708a39f631983f7bf584ed63eb3840a2f212db85efff25b06486
|
4
|
+
data.tar.gz: 14ee38786322a3962cb48bcc64ba5c5d0606750fc24f422ef2c0ed17d962680b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b43275998e160fb9d47db290b973d73b56da8b829ff5e35f408f6cdb093a3dcbf7c990ceabf063733730cbd131be6a9b0369c29113a11f18317c124391656ac
|
7
|
+
data.tar.gz: 5d224524a8d5f42f69cdd5e5b1fc778744e847d918e5cefca08f2115cd23503b8828f154b1f98292df0d1fd4082f79645444f67ddcccb16ff86e15a9bfffed1f
|
data/README.md
CHANGED
@@ -59,6 +59,13 @@ After checking out the repo, run `bin/setup` to install dependencies.
|
|
59
59
|
|
60
60
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
61
61
|
|
62
|
+
### TODOs
|
63
|
+
|
64
|
+
* Custom IAM role policies (Step Functions and Lambda)
|
65
|
+
* sls-like tooling in ruby with AWS SDK
|
66
|
+
* Workflow action unit test support
|
67
|
+
* ...
|
68
|
+
|
62
69
|
## Contributing
|
63
70
|
|
64
71
|
Bug reports and pull requests are (soon - after alpha phase) welcome on GitHub at https://github.com/chtz/simplerubysteps
|
data/lib/deploy.sh
CHANGED
@@ -66,13 +66,14 @@ fi
|
|
66
66
|
echo "Uploading state machine JSON"
|
67
67
|
|
68
68
|
ruby -e 'require "./workflow.rb";puts $sm.render.to_json' > /tmp/my-state-machine-definition.json
|
69
|
+
export WF_TYPE=$(ruby -e 'require "./workflow.rb";puts $sm.kind')
|
69
70
|
export STATE_MACHINE_JSON_SHA=$(shasum /tmp/my-state-machine-definition.json | awk '{print $1}')
|
70
71
|
export UPLOADED_STATE_MACHINE_JSON=statemachine-$STATE_MACHINE_JSON_SHA.zip
|
71
72
|
aws s3 cp /tmp/my-state-machine-definition.json s3://$DEPLOY_BUCKET/$UPLOADED_STATE_MACHINE_JSON
|
72
73
|
|
73
74
|
echo "Updating CloudFormation Stack"
|
74
75
|
|
75
|
-
echo '[{"ParameterKey":"DeployLambda","ParameterValue":"yes"},{"ParameterKey":"DeployStepfunctions","ParameterValue":"yes"},{"ParameterKey":"LambdaS3","ParameterValue":"'$UPLOADED_LAMBDA_ZIP'"},{"ParameterKey":"StepFunctionsS3","ParameterValue":"'$UPLOADED_STATE_MACHINE_JSON'"}]' > /tmp/params.json
|
76
|
+
echo '[{"ParameterKey":"DeployLambda","ParameterValue":"yes"},{"ParameterKey":"DeployStepfunctions","ParameterValue":"yes"},{"ParameterKey":"LambdaS3","ParameterValue":"'$UPLOADED_LAMBDA_ZIP'"},{"ParameterKey":"StepFunctionsS3","ParameterValue":"'$UPLOADED_STATE_MACHINE_JSON'"},{"ParameterKey":"StateMachineType","ParameterValue":"'$WF_TYPE'"}]' > /tmp/params.json
|
76
77
|
|
77
78
|
aws cloudformation deploy \
|
78
79
|
--template-file $CF_TEMPLATE \
|
data/lib/simplerubysteps.rb
CHANGED
@@ -14,9 +14,11 @@ module Simplerubysteps
|
|
14
14
|
class StateMachine
|
15
15
|
attr_reader :states
|
16
16
|
attr_reader :start_at
|
17
|
+
attr_accessor :kind
|
17
18
|
|
18
19
|
def initialize()
|
19
20
|
@states = {}
|
21
|
+
@kind = "STANDARD"
|
20
22
|
end
|
21
23
|
|
22
24
|
def add(state)
|
@@ -76,7 +78,24 @@ module Simplerubysteps
|
|
76
78
|
end
|
77
79
|
|
78
80
|
def perform_action(input)
|
79
|
-
|
81
|
+
output = nil
|
82
|
+
output = @action_block.call(input) if @action_block
|
83
|
+
|
84
|
+
if @implicit_choice
|
85
|
+
output = {} unless output
|
86
|
+
@implicit_choice.perform_action(output)
|
87
|
+
end
|
88
|
+
|
89
|
+
output
|
90
|
+
end
|
91
|
+
|
92
|
+
def implicit_choice
|
93
|
+
unless @implicit_choice
|
94
|
+
@implicit_choice = Choice.new("#{name}_choice")
|
95
|
+
$sm.add @implicit_choice
|
96
|
+
self.next = @implicit_choice
|
97
|
+
end
|
98
|
+
@implicit_choice
|
80
99
|
end
|
81
100
|
end
|
82
101
|
|
@@ -105,6 +124,8 @@ module Simplerubysteps
|
|
105
124
|
end
|
106
125
|
|
107
126
|
class ChoiceItem
|
127
|
+
attr_accessor :implicit_condition_block
|
128
|
+
|
108
129
|
def initialize(dict = {}, state = nil)
|
109
130
|
@dict = dict
|
110
131
|
self.next = state if state
|
@@ -117,6 +138,12 @@ module Simplerubysteps
|
|
117
138
|
def render
|
118
139
|
@dict
|
119
140
|
end
|
141
|
+
|
142
|
+
def perform_action(choice_name, output)
|
143
|
+
if @implicit_condition_block
|
144
|
+
output["#{choice_name}_#{@dict[:Next]}"] = @implicit_condition_block.call(output) ? "yes" : "no"
|
145
|
+
end
|
146
|
+
end
|
120
147
|
end
|
121
148
|
|
122
149
|
class Choice < State
|
@@ -152,12 +179,22 @@ module Simplerubysteps
|
|
152
179
|
dict[:Choices] = @choices.map { |item| item.render }
|
153
180
|
dict
|
154
181
|
end
|
182
|
+
|
183
|
+
def perform_action(output)
|
184
|
+
@choices.each do |choice|
|
185
|
+
choice.perform_action name, output
|
186
|
+
end
|
187
|
+
end
|
155
188
|
end
|
156
189
|
|
157
190
|
# Workflow DSL
|
158
191
|
|
159
192
|
$sm = StateMachine.new
|
160
193
|
$tasks = []
|
194
|
+
|
195
|
+
def kind(k)
|
196
|
+
$sm.kind = k
|
197
|
+
end
|
161
198
|
|
162
199
|
def task(name)
|
163
200
|
t = $sm.add Task.new(name)
|
@@ -187,6 +224,25 @@ module Simplerubysteps
|
|
187
224
|
$tasks.last.next = state
|
188
225
|
end
|
189
226
|
|
227
|
+
def transition_to(state, &condition_block)
|
228
|
+
choice = $tasks.last.implicit_choice
|
229
|
+
|
230
|
+
c = ChoiceItem.new({
|
231
|
+
:Variable => "$.#{choice.name}_#{state}",
|
232
|
+
:StringMatches => "yes",
|
233
|
+
})
|
234
|
+
c.next = state
|
235
|
+
c.implicit_condition_block = condition_block
|
236
|
+
|
237
|
+
choice.add c
|
238
|
+
end
|
239
|
+
|
240
|
+
def default_transition_to(state)
|
241
|
+
choice = $tasks.last.implicit_choice
|
242
|
+
|
243
|
+
choice.default = state
|
244
|
+
end
|
245
|
+
|
190
246
|
def choice(name)
|
191
247
|
t = $sm.add Choice.new(name)
|
192
248
|
|
data/lib/statemachine.yaml
CHANGED
@@ -25,6 +25,10 @@ Parameters:
|
|
25
25
|
- "yes"
|
26
26
|
- "no"
|
27
27
|
ConstraintDescription: must specify yes or no.
|
28
|
+
StateMachineType:
|
29
|
+
Description: StateMachineType.
|
30
|
+
Default: STANDARD
|
31
|
+
Type: String
|
28
32
|
Conditions:
|
29
33
|
CreateLambda: !Equals
|
30
34
|
- !Ref DeployLambda
|
@@ -53,6 +57,7 @@ Resources:
|
|
53
57
|
Bucket: !Ref DeployBucket
|
54
58
|
Key: !Ref StepFunctionsS3
|
55
59
|
RoleArn: !GetAtt StepFunctionsRole.Arn
|
60
|
+
StateMachineType: !Ref StateMachineType
|
56
61
|
MyLambdaRole:
|
57
62
|
Type: AWS::IAM::Role
|
58
63
|
Condition: CreateLambda
|
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
export STACK_NAME=$(basename "$PWD")
|
4
|
+
|
5
|
+
export STEP_FUNCTIONS_ARN=$(aws cloudformation describe-stacks --stack-name $STACK_NAME --output text --query "Stacks[].Outputs[]"|grep StepFunctionsStateMachineARN|awk '{print $2}')
|
6
|
+
|
7
|
+
tee /tmp/statemachineinput.json > /dev/null
|
8
|
+
STATE_MACHINE_INPUT="$(cat /tmp/statemachineinput.json)"
|
9
|
+
|
10
|
+
aws stepfunctions start-sync-execution --state-machine-arn $STEP_FUNCTIONS_ARN --input "$STATE_MACHINE_INPUT" --query "output" --output text
|
data/samples/sample1/workflow.rb
CHANGED
@@ -13,8 +13,7 @@ task :t1 do
|
|
13
13
|
string_matches "$.Foo1", "ja" do
|
14
14
|
callback :t3 do
|
15
15
|
action do |input, token|
|
16
|
-
puts "Callback t3: #{input}, #{token}"
|
17
|
-
# input.merge({ "Foo3": "Bar3x" })
|
16
|
+
puts "Callback t3: #{input}, #{token}" # The logged token is picked up by continue-callbackbranch.sh
|
18
17
|
end
|
19
18
|
|
20
19
|
transition :t5
|
@@ -0,0 +1,42 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require "simplerubysteps"
|
4
|
+
include Simplerubysteps
|
5
|
+
|
6
|
+
kind "EXPRESS"
|
7
|
+
|
8
|
+
task :t1 do
|
9
|
+
action do |input|
|
10
|
+
puts "Task t1: #{input}"
|
11
|
+
input.merge({ "t1" => (input["bar"] ? input["bar"] : "") + "t1" })
|
12
|
+
end
|
13
|
+
|
14
|
+
transition_to :t2 do |output|
|
15
|
+
output["t1"] == "foot1"
|
16
|
+
end
|
17
|
+
|
18
|
+
default_transition_to :t3
|
19
|
+
end
|
20
|
+
|
21
|
+
task :t2 do
|
22
|
+
action do |input|
|
23
|
+
puts "Task t2: #{input}"
|
24
|
+
input.merge({ "t2" => "yes" })
|
25
|
+
end
|
26
|
+
|
27
|
+
transition :t4
|
28
|
+
end
|
29
|
+
|
30
|
+
task :t3 do
|
31
|
+
action do |input|
|
32
|
+
puts "Task t3: #{input}"
|
33
|
+
input.merge({ "t3" => "yes" })
|
34
|
+
end
|
35
|
+
|
36
|
+
task :t4 do
|
37
|
+
action do |input|
|
38
|
+
puts "Task t4: #{input}"
|
39
|
+
input.merge({ "t4" => "yes" })
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
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.5
|
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-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -46,6 +46,7 @@ executables:
|
|
46
46
|
- simplerubysteps-destroy
|
47
47
|
- simplerubysteps-logs
|
48
48
|
- simplerubysteps-workflow-run
|
49
|
+
- simplerubysteps-workflow-run-sync
|
49
50
|
extensions: []
|
50
51
|
extra_rdoc_files: []
|
51
52
|
files:
|
@@ -60,6 +61,7 @@ files:
|
|
60
61
|
- exe/simplerubysteps-destroy
|
61
62
|
- exe/simplerubysteps-logs
|
62
63
|
- exe/simplerubysteps-workflow-run
|
64
|
+
- exe/simplerubysteps-workflow-run-sync
|
63
65
|
- lib/deploy.sh
|
64
66
|
- lib/destroy.sh
|
65
67
|
- lib/function.rb
|
@@ -67,12 +69,14 @@ files:
|
|
67
69
|
- lib/simplerubysteps.rb
|
68
70
|
- lib/simplerubysteps/version.rb
|
69
71
|
- lib/statemachine.yaml
|
72
|
+
- lib/workflow-run-sync.sh
|
70
73
|
- lib/workflow-run.sh
|
71
74
|
- samples/sample1/continue-callbackbranch.sh
|
72
75
|
- samples/sample1/send-task-success.sh
|
73
76
|
- samples/sample1/start-callbackbranch.sh
|
74
77
|
- samples/sample1/start-directbranch.sh
|
75
78
|
- samples/sample1/workflow.rb
|
79
|
+
- samples/sample2/workflow.rb
|
76
80
|
- simplerubysteps.gemspec
|
77
81
|
homepage: https://github.com/chtz/simplerubysteps
|
78
82
|
licenses:
|