-
Notifications
You must be signed in to change notification settings - Fork 0
/
type.go
279 lines (246 loc) · 9.35 KB
/
type.go
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
273
274
275
276
277
278
279
package melonade_client_go
type WorkflowState string
type TransactionStatus string
type WorkflowStatus string
type TaskStatus string
type TaskType string
type CommandType string
type EventType string
const (
WORKFLOW_STATE_RUNNING WorkflowState = "RUNNING"
WORKFLOW_STATE_CANCELLED WorkflowState = "CANCELLED"
WORKFLOW_STATE_FAILED WorkflowState = "FAILED"
WORKFLOW_STATE_PAUSED WorkflowState = "PAUSED"
WORKFLOW_STATE_TIMEOUT WorkflowState = "TIMEOUT"
)
const (
TransactionStatusRunning TransactionStatus = "RUNNING"
TransactionStatusPaused TransactionStatus = "PAUSED"
TransactionStatusCompleted TransactionStatus = "COMPLETED"
TransactionStatusFailed TransactionStatus = "FAILED"
TransactionStatusCancelled TransactionStatus = "CANCELLED"
TransactionStatusCompensated TransactionStatus = "COMPENSATED"
)
const (
WorkflowStatusRunning WorkflowStatus = "RUNNING"
WorkflowStatusPaused WorkflowStatus = "PAUSED"
WorkflowStatusCompleted WorkflowStatus = "COMPLETED"
WorkflowStatusFailed WorkflowStatus = "FAILED"
WorkflowStatusTimeout WorkflowStatus = "TIMEOUT"
WorkflowStatusCancelled WorkflowStatus = "CANCELLED"
)
const (
TaskStatusScheduled TaskStatus = "SCHEDULED"
TaskStatusInProgress TaskStatus = "INPROGRESS"
TaskStatusCompleted TaskStatus = "COMPLETED"
TaskStatusFailed TaskStatus = "FAILED"
TaskStatusTimeout TaskStatus = "TIMEOUT"
TaskStatusAckTimeOut TaskStatus = "ACK_TIMEOUT"
)
const (
TaskTypeTask TaskType = "TASK"
TaskTypeCompensate TaskType = "COMPENSATE"
)
const (
CommandTypeStartTransaction CommandType = "START_TRANSACTION"
)
const (
EventTypeTransaction EventType = "TRANSACTION"
EventTypeWorkflow EventType = "WORKFLOW"
EventTypeTask EventType = "TASK"
EventTypeSystem EventType = "SYSTEM"
)
type ResponseData struct {
TransactionId string `json:"transactionId"`
Status WorkflowState `json:"status"`
Input interface{} `json:"input"`
Output interface{} `json:"output"`
CreateTime int64 `json:"createTime"`
EndTime int64 `json:"endTime"`
}
type ResponseDebug struct {
Method string `json:"method"`
Url string `json:"url"`
Headers interface{} `json:"headers"`
Body interface{} `json:"body"`
Query interface{} `json:"query"`
Params interface{} `json:"params"`
}
type ResponseError struct {
Message string `json:"message"`
Stack string `json:"stack"`
Debug *ResponseDebug `json:"debug"`
}
type StartWorkflowResponse struct {
Success bool `json:"success"`
Data *ResponseData `json:"data"`
Error *ResponseError `json:"error"`
}
type WorkflowDefinition struct {
Name string `json:"name"`
Rev string `json:"rev"`
Description string `json:"description"`
FailureStrategy string `json:"failureStrategy"`
Tasks []interface{} `json:"tasks"`
OutputParameters interface{} `json:"outputParameters"`
Retry struct {
Limit int `json:"limit"`
} `json:"retry"`
}
type TaskDefinition struct {
Name string `json:"name"`
Description string `json:"description"`
AckTimeout int `json:"ackTimeout"`
Retry struct {
Delay int `json:"delay"`
Limit int `json:"limit"`
} `json:"retry"`
SyncWorker bool `json:"syncWorker"`
Timeout int `json:"timeout"`
}
type Transaction struct {
TransactionID string `json:"transactionId"`
Status TransactionStatus `json:"status"`
Input interface{} `json:"input"`
Output interface{} `json:"output"`
CreateTime int64 `json:"createTime"`
EndTime int64 `json:"endTime"`
WorkflowDefinition WorkflowDefinition `json:"workflowDefinition"`
Tags []string `json:"tags"`
}
type Workflow struct {
TransactionID string `json:"transactionId"`
Type string `json:"type"`
WorkflowID string `json:"workflowId"`
Status WorkflowStatus `json:"status"`
Retries int `json:"retries"`
Input interface{} `json:"input"`
Output interface{} `json:"output"`
CreateTime int64 `json:"createTime"`
StartTime int64 `json:"startTime"`
EndTime int64 `json:"endTime"`
WorkflowDefinition WorkflowDefinition `json:"workflowDefinition"`
TransactionDepth int `json:"transactionDepth"`
}
type Task struct {
TaskID string `json:"taskId"`
TaskName string `json:"taskName"`
TaskReferenceName string `json:"taskReferenceName"`
WorkflowID string `json:"workflowId"`
TransactionID string `json:"transactionId"`
Type TaskType `json:"type"`
Status TaskStatus `json:"status"`
IsRetried bool `json:"isRetried"`
Input interface{} `json:"input"`
CreateTime int64 `json:"createTime"`
StartTime int64 `json:"startTime"`
EndTime int64 `json:"endTime"`
Retries int `json:"retries"`
RetryDelay int `json:"retryDelay"`
AckTimeout int `json:"ackTimeout"`
Timeout int `json:"timeout"`
TaskPath []interface{} `json:"taskPath"` // slice of int + string e.g. [0, "parallelTasks", 0, 1]
Output interface{} `json:"output"`
Logs []interface{} `json:"logs"`
}
func (t *Task) ToTaskResult() *TaskResult {
return &TaskResult{
TransactionID: t.TransactionID,
TaskID: t.TaskID,
Status: t.Status,
IsSystem: false,
}
}
type TransactionResult struct {
TransactionID string `json:"transactionId"`
Status TaskStatus `json:"status"`
Output interface{} `json:"output"`
}
type WorkflowResult struct {
TransactionID string `json:"transactionId"`
WorkflowID string `json:"workflowId"`
Status WorkflowStatus `json:"status"`
Output interface{} `json:"output"`
}
type TaskResult struct {
TransactionID string `json:"transactionId"`
TaskID string `json:"taskId"`
Status TaskStatus `json:"status"`
Output interface{} `json:"output"`
Logs []interface{} `json:"logs"` // logs to append
DoNotRetry bool `json:"doNotRetry"` // If task failed do not retry
IsSystem bool `json:"isSystem"` // Internal usage
}
type WorkflowRef struct {
Name string `json:"name"`
Rev string `json:"rev"`
}
type commandStartTransaction struct {
TransactionID string `json:"transactionId"`
Type CommandType `json:"type"` // CommandTypeStartTransaction
WorkflowRef *WorkflowRef `json:"workflowRef,omitempty"`
Input interface{} `json:"input"`
Tags []string `json:"tags"`
}
type BaseEvent struct {
TransactionID string `json:"transactionId"`
Type EventType `json:"type"` // TRANSACTION
IsError bool `json:"isError"` // false
}
type EventTransaction struct {
TransactionID string `json:"transactionId"`
Type EventType `json:"type"` // TRANSACTION
IsError bool `json:"isError"` // false
Timestamp int64 `json:"timestamp"`
Details Transaction `json:"details"`
}
type EventTransactionError struct {
TransactionID string `json:"transactionId"`
Type EventType `json:"type"` // TRANSACTION
IsError bool `json:"isError"` // true
Timestamp int64 `json:"timestamp"`
Details TransactionResult `json:"details"`
}
type EventWorkflow struct {
TransactionID string `json:"transactionId"`
Type EventType `json:"type"` // WORKFLOW
IsError bool `json:"isError"` // false
Timestamp int64 `json:"timestamp"`
Details Workflow `json:"details"`
}
type EventWorkflowError struct {
TransactionID string `json:"transactionId"`
Type EventType `json:"type"` // WORKFLOW
IsError bool `json:"isError"` // true
Timestamp int64 `json:"timestamp"`
Details WorkflowResult `json:"details"`
}
type EventTask struct {
TransactionID string `json:"transactionId"`
Type EventType `json:"type"` // TASK
IsError bool `json:"isError"` // false
Timestamp int64 `json:"timestamp"`
Details Task `json:"details"`
}
type EventTaskError struct {
TransactionID string `json:"transactionId"`
Type EventType `json:"type"` // TASK
IsError bool `json:"isError"` // true
Timestamp int64 `json:"timestamp"`
Details TaskResult `json:"details"`
}
type EventSystem struct {
TransactionID string `json:"transactionId"`
Type EventType `json:"type"` // SYSTEM
IsError bool `json:"isError"` // false
Details interface{} `json:"details"`
Timestamp int64 `json:"timestamp"`
}
type EventSystemError struct {
TransactionID string `json:"transactionId"`
Type EventType `json:"type"` // SYSTEM
IsError bool `json:"isError"` // true
Details interface{} `json:"details"`
Error string `json:"error"`
Timestamp int64 `json:"timestamp"`
}