Repository navigation
Expand file tree
/
Copy pathstateinput.json
More file actions
217 lines (217 loc) · 6.73 KB
/
Copy pathstateinput.json
File metadata and controls
217 lines (217 loc) · 6.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
{
"Comment": "A description of my state machine",
"StartAt": "DynamoDB Get Shop status",
"States": {
"DynamoDB Get Shop status": {
"Type": "Task",
"Resource": "arn:aws:states:::dynamodb:getItem",
"Parameters": {
"TableName": "serverlesspresso-config-table",
"Key": {
"PK": {
"S": "config"
}
}
},
"ResultPath": "$.GetStore",
"Next": "Shop Open?"
},
"Shop Open?": {
"Type": "Choice",
"Choices": [
{
"Not": {
"Variable": "$.GetStore.Item.storeOpen.BOOL",
"BooleanEquals": true
},
"Next": "Emit - Shop not ready"
}
],
"Default": "ListExecutions"
},
"ListExecutions": {
"Type": "Task",
"Next": "Is capacity available?",
"Parameters": {
"StateMachineArn": "arn:aws:states:us-east-1:289685305796:stateMachine:OrderProcessorWorkflow",
"MaxResults": 100,
"StatusFilter": "RUNNING"
},
"Resource": "arn:aws:states:::aws-sdk:sfn:listExecutions",
"ResultPath": "$.isCapacityAvailable"
},
"Is capacity available?": {
"Type": "Choice",
"Choices": [
{
"Variable": "$.isCapacityAvailable.Executions[20]",
"IsPresent": true,
"Next": "Emit - Shop not ready"
}
],
"Default": "Emit - Workflow Started TT"
},
"Emit - Workflow Started TT": {
"Type": "Task",
"Resource": "arn:aws:states:::events:putEvents.waitForTaskToken",
"Parameters": {
"Entries": [
{
"Detail": {
"Message": "The workflow waits for your order to be submitted. It emits an event with a unique 'task token'. The token is stored in an Amazon DynamoDB table, along with your order ID.",
"TaskToken.$": "$$.Task.Token",
"orderId.$": "$.detail.orderId",
"userId.$": "$.detail.userId"
},
"DetailType": "OrderProcessor.WorkflowStarted",
"EventBusName": "Serverlesspresso",
"Source": "awsserverlessda.serverlesspresso"
}
]
},
"Next": "Generate Order Number",
"ResultPath": null,
"Catch": [
{
"ErrorEquals": [
"States.Timeout"
],
"Comment": "Customer timed out",
"Next": "Customer timedout"
}
],
"HeartbeatSeconds": 900
},
"Customer timedout": {
"Type": "Pass",
"Comment": "\"Customer timedout\"",
"Result": "Customer timedout",
"ResultPath": "$.cause",
"Next": "Emit - error timeout"
},
"Emit - error timeout": {
"Type": "Task",
"Resource": "arn:aws:states:::events:putEvents",
"Parameters": {
"Entries": [
{
"Detail": {
"Message": "The order timed out. Step Functions waits a set amount of time (5 minutes for a customer, 15 minutes for a barista), no action was taken and so the order is ended.",
"userId.$": "$.detail.userId",
"orderId.$": "$.detail.orderId",
"cause.$": "$.cause"
},
"DetailType": "OrderProcessor.OrderTimeOut",
"EventBusName": "Serverlesspresso",
"Source": "awsserverlessda.serverlesspresso"
}
]
},
"End": true
},
"Generate Order Number": {
"Type": "Task",
"Resource": "arn:aws:states:::dynamodb:updateItem",
"Parameters": {
"TableName": "serverlesspresso-counting-table",
"Key": {
"PK": {
"S": "orderID"
}
},
"UpdateExpression": "set IDvalue = IDvalue + :val",
"ExpressionAttributeValues": {
":val": {
"N": "1"
}
},
"ReturnValues": "UPDATED_NEW"
},
"Next": "Emit - Awaiting Completion TT",
"ResultSelector": {
"orderNumber.$": "$.Attributes.IDvalue.N"
},
"ResultPath": "$.Order.Payload"
},
"Emit - Awaiting Completion TT": {
"Type": "Task",
"Resource": "arn:aws:states:::events:putEvents.waitForTaskToken",
"Parameters": {
"Entries": [
{
"Detail": {
"Message": "You pressed 'submit order'. The workflow resumes using the stored 'task token', it generates your order number. It then pauses again, emitting an event with a new 'task token'.",
"TaskToken.$": "$$.Task.Token",
"orderId.$": "$.detail.orderId",
"orderNumber.$": "$.Order.Payload.orderNumber",
"userId.$": "$.detail.userId"
},
"DetailType": "OrderProcessor.WaitingCompletion",
"EventBusName": "Serverlesspresso",
"Source": "awsserverlessda.serverlesspresso"
}
]
},
"Next": "Pass",
"ResultPath": "$.order",
"Catch": [
{
"ErrorEquals": [
"States.Timeout"
],
"Comment": "Barista timed out",
"Next": "Barista timedout",
"ResultPath": "$.comment"
}
],
"HeartbeatSeconds": 900
},
"Barista timedout": {
"Type": "Pass",
"Result": "Barista timedout",
"ResultPath": "$.cause",
"Next": "Emit - error timeout"
},
"Emit - Shop not ready": {
"Type": "Task",
"Resource": "arn:aws:states:::events:putEvents",
"Parameters": {
"Entries": [
{
"Detail": {
"Message": "The Step functions workflow checks if the shop is open and has capacity to serve a new order by invoking a Lambda function that queries the Shop config service. The shop was not ready, and so a 'not ready' event is emitted to cancel the current order.",
"userId.$": "$.detail.userId"
},
"DetailType": "OrderProcessor.ShopUnavailable",
"EventBusName": "Serverlesspresso",
"Source": "awsserverlessda.serverlesspresso"
}
]
},
"End": true
},
"Pass": {
"Type": "Pass",
"Next": "Emit - order finished"
},
"Emit - order finished": {
"Type": "Task",
"Resource": "arn:aws:states:::events:putEvents",
"Parameters": {
"Entries": [
{
"Detail": {
"Message": "The order has reached the end of the workflow, and so a final event is emitted to alert other services to this.",
"userId.$": "$.detail.userId",
"orderId.$": "$.detail.orderId"
},
"DetailType": "OrderProcessor.orderFinished",
"EventBusName": "Serverlesspresso",
"Source": "awsserverlessda.serverlesspresso"
}
]
},
"End": true
}
}
}