-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathmodels.go
More file actions
246 lines (215 loc) · 8.69 KB
/
Copy pathmodels.go
File metadata and controls
246 lines (215 loc) · 8.69 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
package floxy
import (
"encoding/json"
"time"
)
type Priority int
const (
PriorityLow Priority = 0
PriorityLower Priority = 25
PriorityNormal Priority = 50
PriorityHigher Priority = 75
PriorityHigh Priority = 100
)
type WorkflowStatus string
const (
StatusPending WorkflowStatus = "pending"
StatusRunning WorkflowStatus = "running"
StatusCompleted WorkflowStatus = "completed"
StatusFailed WorkflowStatus = "failed"
StatusRollingBack WorkflowStatus = "rolling_back"
StatusCancelling WorkflowStatus = "cancelling"
StatusCancelled WorkflowStatus = "cancelled"
StatusAborted WorkflowStatus = "aborted"
StatusDLQ WorkflowStatus = "dlq"
)
type StepStatus string
const (
StepStatusPending StepStatus = "pending"
StepStatusRunning StepStatus = "running"
StepStatusCompleted StepStatus = "completed"
StepStatusFailed StepStatus = "failed"
StepStatusSkipped StepStatus = "skipped"
StepStatusCompensation StepStatus = "compensation"
StepStatusRolledBack StepStatus = "rolled_back"
StepStatusWaitingDecision StepStatus = "waiting_decision"
StepStatusConfirmed StepStatus = "confirmed"
StepStatusRejected StepStatus = "rejected"
StepStatusPaused StepStatus = "paused"
)
type StepType string
const (
StepTypeTask StepType = "task"
StepTypeParallel StepType = "parallel"
StepTypeCondition StepType = "condition"
StepTypeFork StepType = "fork"
StepTypeJoin StepType = "join"
StepTypeSavePoint StepType = "save_point"
StepTypeHuman StepType = "human"
)
type JoinStrategy string
const (
JoinStrategyAll JoinStrategy = "all"
JoinStrategyAny JoinStrategy = "any"
)
type HumanDecision string
const (
HumanDecisionConfirmed HumanDecision = "confirmed"
HumanDecisionRejected HumanDecision = "rejected"
)
type CancelType string
const (
CancelTypeCancel CancelType = "cancel"
CancelTypeAbort CancelType = "abort"
)
type RetryStrategy uint8
const (
RetryStrategyFixed RetryStrategy = iota // Fixed delay between retries
RetryStrategyExponential // Exponential backoff: delay = base * 2^attempt
RetryStrategyLinear // Linear backoff: delay = base * attempt
)
type WorkflowDefinition struct {
ID string `json:"id"`
Name string `json:"name"`
Version int `json:"version"`
Definition GraphDefinition `json:"definition"`
CreatedAt time.Time `json:"created_at"`
}
type GraphDefinition struct {
Steps map[string]*StepDefinition `json:"steps"`
Start string `json:"start"`
DLQEnabled bool `json:"dlq_enabled"`
}
type StepDefinition struct {
Name string `json:"name"`
Type StepType `json:"type"`
Handler string `json:"handler"`
MaxRetries int `json:"max_retries"`
Next []string `json:"next,omitempty"`
Prev string `json:"prev,omitempty"` // previous step in the chain
Else string `json:"else,omitempty"` // alternative step for condition steps for false branch
OnFailure string `json:"on_failure,omitempty"` // compensation step
Condition string `json:"condition,omitempty"` // for conditional transitions
Parallel []string `json:"parallel,omitempty"` // for parallel steps (fork)
WaitFor []string `json:"wait_for,omitempty"` // for join, we are waiting for these steps to be completed
JoinStrategy JoinStrategy `json:"join_strategy,omitempty"` // "all" (default) or "any"
Metadata map[string]any `json:"metadata,omitempty"`
NoIdempotent bool `json:"no_idempotent"`
Delay time.Duration `json:"delay,omitempty"`
RetryDelay time.Duration `json:"retry_delay,omitempty"`
RetryStrategy RetryStrategy `json:"retry_strategy,omitempty"` // Strategy for retry delays: fixed, exponential, linear
Timeout time.Duration `json:"timeout,omitempty"`
}
type WorkflowInstance struct {
ID int64 `json:"id"`
WorkflowID string `json:"workflow_id"`
Status WorkflowStatus `json:"status"`
Input json.RawMessage `json:"input"`
Output json.RawMessage `json:"output"`
Error *string `json:"error"`
StartedAt *time.Time `json:"started_at"`
CompletedAt *time.Time `json:"completed_at"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type WorkflowStep struct {
ID int64 `json:"id"`
InstanceID int64 `json:"instance_id"`
StepName string `json:"step_name"`
StepType StepType `json:"step_type"`
Status StepStatus `json:"status"`
Input json.RawMessage `json:"input"`
Output json.RawMessage `json:"output"`
Error *string `json:"error"`
RetryCount int `json:"retry_count"`
MaxRetries int `json:"max_retries"`
CompensationRetryCount int `json:"compensation_retry_count"`
IdempotencyKey string `json:"idempotency_key"`
StartedAt *time.Time `json:"started_at"`
CompletedAt *time.Time `json:"completed_at"`
CreatedAt time.Time `json:"created_at"`
}
type QueueItem struct {
ID int64 `json:"id"`
InstanceID int64 `json:"instance_id"`
StepID *int64 `json:"step_id"`
ScheduledAt time.Time `json:"scheduled_at"`
AttemptedAt *time.Time `json:"attempted_at"`
AttemptedBy *string `json:"attempted_by"`
Priority int `json:"priority"`
}
type WorkflowEvent struct {
ID int64 `json:"id"`
InstanceID int64 `json:"instance_id"`
StepID *int64 `json:"step_id"`
EventType string `json:"event_type"`
Payload json.RawMessage `json:"payload"`
CreatedAt time.Time `json:"created_at"`
}
type WorkflowCancelRequest struct {
ID int64 `json:"id"`
InstanceID int64 `json:"instance_id"`
RequestedBy string `json:"requested_by"`
CancelType CancelType `json:"cancel_type"`
Reason *string `json:"reason"`
CreatedAt time.Time `json:"created_at"`
}
type JoinState struct {
InstanceID int64 `json:"instance_id"`
JoinStepName string `json:"join_step_name"`
WaitingFor []string `json:"waiting_for"`
Completed []string `json:"completed"`
Failed []string `json:"failed"`
JoinStrategy JoinStrategy `json:"join_strategy"`
IsReady bool `json:"is_ready"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type SummaryStats struct {
TotalWorkflows uint `json:"total_workflows"`
CompletedWorkflows uint `json:"completed_workflows"`
FailedWorkflows uint `json:"failed_workflows"`
RunningWorkflows uint `json:"running_workflows"`
PendingWorkflows uint `json:"pending_workflows"`
ActiveWorkflows uint `json:"active_workflows"`
}
type ActiveWorkflowInstance struct {
ID int64 `json:"id"`
WorkflowID string `json:"workflow_id"`
WorkflowName string `json:"workflow_name"`
Status string `json:"status"`
StartedAt time.Time `json:"started_at"`
UpdatedAt time.Time `json:"updated_at"`
CurrentStep string `json:"current_step"`
TotalSteps int `json:"total_steps"`
CompletedSteps int `json:"completed_steps"`
RolledBackSteps int `json:"rolled_back_steps"`
}
type HumanDecisionRecord struct {
ID int64 `json:"id"`
InstanceID int64 `json:"instance_id"`
StepID int64 `json:"step_id"`
DecidedBy string `json:"decided_by"`
Decision HumanDecision `json:"decision"`
Comment *string `json:"comment"`
DecidedAt time.Time `json:"decided_at"`
CreatedAt time.Time `json:"created_at"`
}
type HumanDecisionWaitingEvent struct {
InstanceID int64 `json:"instance_id"`
OutputData json.RawMessage `json:"output_data"`
}
// DeadLetterRecord represents a record stored in the Dead Letter Queue
// used to resume failed steps later.
type DeadLetterRecord struct {
ID int64 `json:"id"`
InstanceID int64 `json:"instance_id"`
WorkflowID string `json:"workflow_id"`
StepID int64 `json:"step_id"`
StepName string `json:"step_name"`
StepType string `json:"step_type"`
Input json.RawMessage `json:"input"`
Error *string `json:"error"`
Reason string `json:"reason"`
CreatedAt time.Time `json:"created_at"`
}