-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstate-machine-workflow.yaml
More file actions
272 lines (225 loc) · 7.24 KB
/
state-machine-workflow.yaml
File metadata and controls
272 lines (225 loc) · 7.24 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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
# State Machine Workflow Example Configuration
# This demonstrates a workflow that tracks explicit states and transitions
requires:
plugins:
- name: api
- name: messaging
- name: statemachine
- name: workflow-plugin-http
modules:
# State machine engine
- name: order-processor
type: statemachine.engine
config:
description: "Processes orders through their lifecycle"
# State tracker modules
- name: workflow.service.statetracker
type: state.tracker
config:
description: "Tracks state for workflow resources"
- name: workflow.connector.statemachine
type: state.connector
dependsOn:
- workflow.service.statetracker
config:
description: "Connects state machines to resources"
# Event broker for transition notifications
- name: transition-broker
type: messaging.broker
config:
description: "Message broker for state transitions"
# State transition handlers
- name: order-validation-handler
type: messaging.handler
config:
description: "Handles order validation processing"
- name: payment-processing-handler
type: messaging.handler
config:
description: "Handles payment processing"
- name: fulfillment-handler
type: messaging.handler
config:
description: "Handles order fulfillment"
- name: notification-handler
type: messaging.handler
config:
description: "Sends notifications based on state transitions"
# API server for receiving orders and status updates
- name: http-server
type: http.server
config:
address: ":8080"
- name: api-router
type: http.router
dependsOn:
- http-server
- name: logging-middleware
type: http.middleware.logging
config:
logLevel: "info"
- name: order-api
type: api.handler
dependsOn:
- api-router
config:
resourceName: "orders"
workflowType: "order-workflow"
workflowEngine: "order-processor"
instanceIDPrefix: "order-"
instanceIDField: "id"
workflows:
# HTTP routes for API
http:
router: api-router
server: http-server
routes:
- method: "POST"
path: "/api/orders"
handler: order-api
middlewares:
- logging-middleware
- method: "GET"
path: "/api/orders"
handler: order-api
middlewares:
- logging-middleware
- method: "GET"
path: "/api/orders/{id}"
handler: order-api
middlewares:
- logging-middleware
- method: "PUT"
path: "/api/orders/{id}/transition"
handler: order-api
middlewares:
- logging-middleware
# State machine workflow definition
statemachine:
# Define the state machine engine to use
engine: order-processor
# Define resource mappings to state machines
resourceMappings:
- resourceType: "orders"
stateMachine: "order-processor"
instanceIDKey: "id"
# Define workflow definitions
definitions:
# Order processing workflow
- name: order-workflow
description: "E-commerce order processing workflow"
initialState: "new"
# Define all possible states
states:
new:
description: "Order has been created but not validated"
isFinal: false
isError: false
validating:
description: "Order is being validated"
isFinal: false
isError: false
invalid:
description: "Order failed validation"
isFinal: true
isError: true
validated:
description: "Order has been validated and ready for payment"
isFinal: false
isError: false
payment_pending:
description: "Awaiting payment processing"
isFinal: false
isError: false
payment_failed:
description: "Payment processing failed"
isFinal: false
isError: true
paid:
description: "Payment has been received"
isFinal: false
isError: false
fulfillment_pending:
description: "Order is being prepared for shipping"
isFinal: false
isError: false
shipped:
description: "Order has been shipped"
isFinal: false
isError: false
delivered:
description: "Order has been delivered"
isFinal: true
isError: false
cancelled:
description: "Order has been cancelled"
isFinal: true
isError: false
refunded:
description: "Order has been refunded"
isFinal: true
isError: false
# Define possible transitions between states
transitions:
submit_order:
fromState: "new"
toState: "validating"
autoTransform: true
validation_passed:
fromState: "validating"
toState: "validated"
validation_failed:
fromState: "validating"
toState: "invalid"
process_payment:
fromState: "validated"
toState: "payment_pending"
payment_succeeded:
fromState: "payment_pending"
toState: "paid"
payment_declined:
fromState: "payment_pending"
toState: "payment_failed"
retry_payment:
fromState: "payment_failed"
toState: "payment_pending"
fulfill:
fromState: "paid"
toState: "fulfillment_pending"
autoTransform: true
ship:
fromState: "fulfillment_pending"
toState: "shipped"
deliver:
fromState: "shipped"
toState: "delivered"
cancel:
fromState: "new"
toState: "cancelled"
cancel_after_validation:
fromState: "validated"
toState: "cancelled"
cancel_after_payment:
fromState: "paid"
toState: "refunded"
refund_shipped:
fromState: "shipped"
toState: "refunded"
# Define hooks for transitions
hooks:
# Validation processing hook
- workflowType: "order-workflow"
transitions: ["submit_order"]
handler: "order-validation-handler"
# Payment processing hook
- workflowType: "order-workflow"
transitions: ["process_payment", "retry_payment"]
handler: "payment-processing-handler"
# Fulfillment hook
- workflowType: "order-workflow"
transitions: ["fulfill", "ship"]
handler: "fulfillment-handler"
# General notification hook for all state changes
- workflowType: "order-workflow"
toStates: ["validated", "paid", "shipped", "delivered", "cancelled", "refunded"]
handler: "notification-handler"