@@ -19,14 +19,13 @@ import (
19
19
20
20
// QueueFilter contains all criteria used to fetch queue
21
21
type QueueFilter struct {
22
- ModelType []string
23
- RatioService * int
24
- Rights int
25
- Since * time.Time
26
- Until * time.Time
27
- Limit * int
28
- Statuses []string
29
- Regions []string
22
+ ModelType []string
23
+ Rights int
24
+ Since * time.Time
25
+ Until * time.Time
26
+ Limit * int
27
+ Statuses []string
28
+ Regions []string
30
29
}
31
30
32
31
func NewQueueFilter () QueueFilter {
@@ -79,38 +78,27 @@ func CountNodeJobRunQueueByGroupIDs(ctx context.Context, db gorp.SqlExecutor, st
79
78
func LoadNodeJobRunQueue (ctx context.Context , db gorp.SqlExecutor , store cache.Store , filter QueueFilter ) ([]sdk.WorkflowNodeJobRun , error ) {
80
79
ctx , end := telemetry .Span (ctx , "workflow.LoadNodeJobRunQueue" )
81
80
defer end ()
82
- containsService := []bool {true , false }
83
- if filter .RatioService != nil {
84
- if * filter .RatioService == 100 {
85
- containsService = []bool {true , true }
86
- } else if * filter .RatioService == 0 {
87
- containsService = []bool {false , false }
88
- }
89
- }
90
81
91
82
query := gorpmapping .NewQuery (`select distinct workflow_node_run_job.*
92
83
from workflow_node_run_job
93
84
where workflow_node_run_job.queued >= $1
94
85
and workflow_node_run_job.queued <= $2
95
86
and workflow_node_run_job.status = ANY($3)
96
- AND contains_service IN ($4, $5)
97
- AND (model_type is NULL OR model_type = '' OR model_type = ANY($6))
87
+ AND (model_type is NULL OR model_type = '' OR model_type = ANY($4))
98
88
AND (
99
- workflow_node_run_job.region = ANY($7 )
89
+ workflow_node_run_job.region = ANY($5 )
100
90
OR
101
- (workflow_node_run_job.region is NULL AND '' = ANY($7 ))
91
+ (workflow_node_run_job.region is NULL AND '' = ANY($5 ))
102
92
OR
103
- array_length($7 , 1) is NULL
93
+ array_length($5 , 1) is NULL
104
94
)
105
95
ORDER BY workflow_node_run_job.queued ASC
106
96
` ).Args (
107
97
* filter .Since , // $1
108
98
* filter .Until , // $2
109
99
pq .StringArray (filter .Statuses ), // $3
110
- containsService [0 ], // $4
111
- containsService [1 ], // $5
112
- pq .StringArray (filter .ModelType ), // $6
113
- pq .StringArray (filter .Regions ), // $7
100
+ pq .StringArray (filter .ModelType ), // $4
101
+ pq .StringArray (filter .Regions ), // $5
114
102
)
115
103
116
104
return loadNodeJobRunQueue (ctx , db , store , query , filter .Limit )
@@ -120,45 +108,36 @@ func LoadNodeJobRunQueue(ctx context.Context, db gorp.SqlExecutor, store cache.S
120
108
func LoadNodeJobRunQueueByGroupIDs (ctx context.Context , db gorp.SqlExecutor , store cache.Store , filter QueueFilter , groupIDs []int64 ) ([]sdk.WorkflowNodeJobRun , error ) {
121
109
ctx , end := telemetry .Span (ctx , "workflow.LoadNodeJobRunQueueByGroups" )
122
110
defer end ()
123
- containsService := []bool {true , false }
124
- if filter .RatioService != nil {
125
- if * filter .RatioService == 100 {
126
- containsService = []bool {true , true }
127
- } else if * filter .RatioService == 0 {
128
- containsService = []bool {false , false }
129
- }
130
- }
131
111
132
112
query := gorpmapping .NewQuery (`
133
113
-- Parameters:
134
114
-- $1: Queue since
135
115
-- $2: Queue until
136
116
-- $3: List of status
137
- -- $4, $5: Should (or should not) contains service, or we don't care
138
- -- $6: List of model types
139
- -- $7: Comman separated list of groups ID
140
- -- $8: shared infra group ID
141
- -- $9: minimum level of permission
142
- -- $10: List of regions
117
+ -- $4: List of model types
118
+ -- $5: Comman separated list of groups ID
119
+ -- $6: shared infra group ID
120
+ -- $7: minimum level of permission
121
+ -- $8: List of regions
143
122
WITH workflow_id_with_permissions AS (
144
123
SELECT workflow_perm.workflow_id,
145
- CASE WHEN $8 = ANY(string_to_array($7 , ',')::int[]) THEN 7
124
+ CASE WHEN $6 = ANY(string_to_array($5 , ',')::int[]) THEN 7
146
125
ELSE max(workflow_perm.role)
147
126
END as "role"
148
127
FROM workflow_perm
149
128
JOIN project_group ON project_group.id = workflow_perm.project_group_id
150
129
WHERE
151
- project_group.group_id = ANY(string_to_array($7 , ',')::int[])
130
+ project_group.group_id = ANY(string_to_array($5 , ',')::int[])
152
131
OR
153
- $8 = ANY(string_to_array($7 , ',')::int[])
132
+ $6 = ANY(string_to_array($5 , ',')::int[])
154
133
GROUP BY workflow_perm.workflow_id
155
134
), workflow_node_run_job_exec_groups AS (
156
135
SELECT id, jsonb_array_elements_text(exec_groups)::jsonb->'id' AS exec_group_id
157
136
FROM workflow_node_run_job
158
137
), workflow_node_run_job_matching_exec_groups AS (
159
138
SELECT id
160
139
FROM workflow_node_run_job_exec_groups
161
- WHERE exec_group_id::text = ANY(string_to_array($7 , ','))
140
+ WHERE exec_group_id::text = ANY(string_to_array($5 , ','))
162
141
)
163
142
SELECT DISTINCT workflow_node_run_job.*
164
143
FROM workflow_node_run_job
@@ -168,7 +147,7 @@ func LoadNodeJobRunQueueByGroupIDs(ctx context.Context, db gorp.SqlExecutor, sto
168
147
WHERE workflow.id IN (
169
148
SELECT workflow_id
170
149
FROM workflow_id_with_permissions
171
- WHERE role >= $9
150
+ WHERE role >= $7
172
151
)
173
152
AND workflow_node_run_job.id IN (
174
153
SELECT id
@@ -177,31 +156,28 @@ func LoadNodeJobRunQueueByGroupIDs(ctx context.Context, db gorp.SqlExecutor, sto
177
156
AND workflow_node_run_job.queued >= $1
178
157
AND workflow_node_run_job.queued <= $2
179
158
AND workflow_node_run_job.status = ANY($3)
180
- AND workflow_node_run_job.contains_service IN ($4, $5)
181
159
AND (
182
160
workflow_node_run_job.model_type is NULL
183
161
OR
184
- model_type = '' OR model_type = ANY($6 )
162
+ model_type = '' OR model_type = ANY($4 )
185
163
)
186
164
AND (
187
- workflow_node_run_job.region = ANY($10 )
165
+ workflow_node_run_job.region = ANY($8 )
188
166
OR
189
- (workflow_node_run_job.region is NULL AND '' = ANY($10 ))
167
+ (workflow_node_run_job.region is NULL AND '' = ANY($8 ))
190
168
OR
191
- array_length($10 , 1) is NULL
169
+ array_length($8 , 1) is NULL
192
170
)
193
171
ORDER BY workflow_node_run_job.queued ASC
194
172
` ).Args (
195
173
* filter .Since , // $1
196
174
* filter .Until , // $2
197
175
pq .StringArray (filter .Statuses ), // $3
198
- containsService [0 ], // $4
199
- containsService [1 ], // $5
200
- pq .StringArray (filter .ModelType ), // $6
201
- gorpmapping .IDsToQueryString (groupIDs ), // $7
202
- group .SharedInfraGroup .ID , // $8
203
- filter .Rights , // $9
204
- pq .StringArray (filter .Regions ), // $10
176
+ pq .StringArray (filter .ModelType ), // $4
177
+ gorpmapping .IDsToQueryString (groupIDs ), // $5
178
+ group .SharedInfraGroup .ID , // $6
179
+ filter .Rights , // $7
180
+ pq .StringArray (filter .Regions ), // $8
205
181
)
206
182
return loadNodeJobRunQueue (ctx , db , store , query , filter .Limit )
207
183
}
0 commit comments