-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworkflow.json
More file actions
156 lines (156 loc) · 4.86 KB
/
workflow.json
File metadata and controls
156 lines (156 loc) · 4.86 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
{
"name": "order-processing",
"description": "Check stock, process payment if available, and notify fulfillment or out-of-stock.",
"category": "commerce",
"features": ["condition", "http", "retry"],
"input_schema": {
"type": "object",
"required": ["order", "stock_api_url", "payment_api_url", "fulfillment_api_url", "notification_api_url"],
"properties": {
"order": {
"type": "object",
"description": "Order data with id, product, quantity, and price",
"properties": {
"id": { "type": "string" },
"product": { "type": "string" },
"quantity": { "type": "number" },
"price": { "type": "number" }
},
"required": ["id", "product", "quantity", "price"]
},
"stock_api_url": {
"type": "string",
"description": "API endpoint to check product stock"
},
"payment_api_url": {
"type": "string",
"description": "API endpoint to process payment"
},
"fulfillment_api_url": {
"type": "string",
"description": "API endpoint to notify fulfillment"
},
"notification_api_url": {
"type": "string",
"description": "API endpoint for customer notifications"
}
}
},
"definition": {
"timeout": "5m",
"on_timeout": "fail",
"steps": [
{
"id": "check-stock",
"type": "action",
"action": "http.get",
"params": {
"url": "${{inputs.stock_api_url}}",
"headers": {
"X-Product": "${{inputs.order.product}}",
"X-Quantity": "${{inputs.order.quantity}}"
}
},
"timeout": "15s",
"retry": {
"max": 2,
"backoff": "exponential",
"delay": "1s"
}
},
{
"id": "stock-decision",
"type": "condition",
"depends_on": ["check-stock"],
"config": {
"expression": "steps['check-stock'].body.available == true",
"branches": {
"true": [
{
"id": "process-payment",
"type": "action",
"action": "http.post",
"params": {
"url": "${{inputs.payment_api_url}}",
"body": {
"order_id": "${{inputs.order.id}}",
"product": "${{inputs.order.product}}",
"quantity": "${{inputs.order.quantity}}",
"price": "${{inputs.order.price}}"
}
},
"timeout": "30s",
"retry": {
"max": 2,
"backoff": "exponential",
"delay": "2s"
}
},
{
"id": "notify-fulfillment",
"type": "action",
"action": "http.post",
"depends_on": ["process-payment"],
"params": {
"url": "${{inputs.fulfillment_api_url}}",
"body": {
"order_id": "${{inputs.order.id}}",
"product": "${{inputs.order.product}}",
"quantity": "${{inputs.order.quantity}}"
}
},
"timeout": "15s",
"retry": {
"max": 2,
"backoff": "exponential",
"delay": "1s"
}
},
{
"id": "send-confirmation",
"type": "action",
"action": "http.post",
"depends_on": ["notify-fulfillment"],
"params": {
"url": "${{inputs.notification_api_url}}",
"body": {
"order_id": "${{inputs.order.id}}",
"subject": "Order Confirmed",
"message": "Your order has been confirmed and sent to fulfillment."
}
},
"timeout": "15s",
"retry": {
"max": 2,
"backoff": "exponential",
"delay": "1s"
}
}
]
},
"default": [
{
"id": "notify-out-of-stock",
"type": "action",
"action": "http.post",
"params": {
"url": "${{inputs.notification_api_url}}",
"body": {
"order_id": "${{inputs.order.id}}",
"subject": "Out of Stock",
"message": "Product is currently out of stock. We will notify you when it becomes available."
}
},
"timeout": "15s",
"retry": {
"max": 2,
"backoff": "exponential",
"delay": "1s"
}
}
]
}
}
]
}
}