-
Notifications
You must be signed in to change notification settings - Fork 39
/
basic_view.go
106 lines (82 loc) · 2.35 KB
/
basic_view.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
package workflowexecution
import (
"github.com/seal-io/walrus/pkg/apis/runtime"
"github.com/seal-io/walrus/pkg/dao/model"
"github.com/seal-io/walrus/pkg/dao/model/predicate"
"github.com/seal-io/walrus/pkg/dao/model/workflowexecution"
"github.com/seal-io/walrus/pkg/dao/types/object"
"github.com/seal-io/walrus/pkg/dao/types/status"
"github.com/seal-io/walrus/utils/errorx"
)
type (
GetRequest struct {
model.WorkflowExecutionQueryInput `path:",inline"`
}
GetResponse = *model.WorkflowExecutionOutput
)
type UpdateRequest struct {
model.WorkflowExecutionUpdateInput `path:",inline" json:",inline"`
Status string `json:"status"`
}
func (r *UpdateRequest) Validate() error {
if err := r.WorkflowExecutionUpdateInput.Validate(); err != nil {
return err
}
return nil
}
type (
CollectionGetRequest struct {
model.WorkflowExecutionQueryInputs `path:",inline"`
runtime.RequestCollection[
predicate.WorkflowExecution, workflowexecution.OrderOption,
] `query:",inline"`
Stream *runtime.RequestUnidiStream
ID object.ID `query:"id"`
}
CollectionGetResponse []*model.WorkflowExecutionOutput
)
func (r *CollectionGetRequest) SetStream(stream runtime.RequestUnidiStream) {
r.Stream = &stream
}
type (
DeleteRequest struct {
model.WorkflowExecutionQueryInput `path:",inline"`
}
DeleteResponse = *model.WorkflowExecutionDeleteInput
)
func (r *DeleteRequest) Validate() error {
err := r.WorkflowExecutionQueryInput.Validate()
if err != nil {
return err
}
workflowExecution, err := r.Client.WorkflowExecutions().Query().
Where(workflowexecution.ID(r.ID)).
Only(r.Context)
if err != nil {
return err
}
if status.WorkflowExecutionStatusRunning.IsUnknown(workflowExecution) {
return errorx.Errorf("workflow execution %s is running", workflowExecution.ID.String())
}
return nil
}
type CollectionDeleteRequest struct {
model.WorkflowExecutionDeleteInputs
}
func (r *CollectionDeleteRequest) Validate() error {
ids := r.IDs()
executions, err := r.Client.WorkflowExecutions().Query().
Where(workflowexecution.IDIn(ids...)).
Select(workflowexecution.FieldID).
All(r.Context)
if err != nil {
return err
}
for i := range executions {
execution := executions[i]
if status.WorkflowExecutionStatusRunning.IsUnknown(execution) {
return errorx.Errorf("workflow execution %s is running", execution.ID.String())
}
}
return nil
}