@@ -20,9 +20,6 @@ import (
20
20
"fmt"
21
21
"time"
22
22
23
- util2 "github.com/devtron-labs/devtron/internal/util"
24
-
25
- "github.com/devtron-labs/devtron/api/bean"
26
23
"github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig"
27
24
"github.com/go-pg/pg"
28
25
"go.uber.org/zap"
@@ -31,14 +28,10 @@ import (
31
28
type WorkflowStatusLatestService interface {
32
29
// CI Workflow Status Latest methods
33
30
SaveCiWorkflowStatusLatest (tx * pg.Tx , pipelineId , appId , ciWorkflowId int , userId int32 ) error
34
- GetCiWorkflowStatusLatestByPipelineId (pipelineId int ) (* CiWorkflowStatusLatest , error )
35
- GetCiWorkflowStatusLatestByAppId (appId int ) ([]* CiWorkflowStatusLatest , error )
31
+ GetCiWorkflowStatusLatestByPipelineIds (pipelineIds []int ) ([]* pipelineConfig.CiWorkflowStatusLatest , error )
36
32
37
33
// CD Workflow Status Latest methods
38
34
SaveCdWorkflowStatusLatest (tx * pg.Tx , pipelineId , appId , environmentId , workflowRunnerId int , workflowType string , userId int32 ) error
39
- GetCdWorkflowStatusLatestByPipelineIdAndWorkflowType (pipelineId int , workflowType string ) (* CdWorkflowStatusLatest , error )
40
- GetCdWorkflowStatusLatestByAppId (appId int ) ([]* CdWorkflowStatusLatest , error )
41
- GetCdWorkflowStatusLatestByPipelineId (pipelineId int ) ([]* CdWorkflowStatusLatest , error )
42
35
GetCdWorkflowLatestByPipelineIds (pipelineIds []int ) ([]* CdWorkflowStatusLatest , error )
43
36
}
44
37
@@ -104,58 +97,8 @@ func (impl *WorkflowStatusLatestServiceImpl) SaveCiWorkflowStatusLatest(tx *pg.T
104
97
return impl .workflowStatusLatestRepository .SaveCiWorkflowStatusLatest (tx , model )
105
98
}
106
99
107
- func (impl * WorkflowStatusLatestServiceImpl ) GetCiWorkflowStatusLatestByPipelineId (pipelineId int ) (* CiWorkflowStatusLatest , error ) {
108
- model , err := impl .workflowStatusLatestRepository .GetCiWorkflowStatusLatestByPipelineId (pipelineId )
109
- if err != nil {
110
- if err == pg .ErrNoRows {
111
- // Fallback to old method
112
- return impl .getCiWorkflowStatusFromOldMethod (pipelineId )
113
- }
114
- impl .logger .Errorw ("error in getting ci workflow status latest" , "err" , err , "pipelineId" , pipelineId )
115
- return nil , err
116
- }
117
-
118
- // Get status from ci_workflow table
119
- ciWorkflow , err := impl .ciWorkflowRepository .FindById (model .CiWorkflowId )
120
- if err != nil {
121
- impl .logger .Errorw ("error in getting ci workflow" , "err" , err , "ciWorkflowId" , model .CiWorkflowId )
122
- return nil , err
123
- }
124
-
125
- return & CiWorkflowStatusLatest {
126
- PipelineId : model .PipelineId ,
127
- AppId : model .AppId ,
128
- CiWorkflowId : model .CiWorkflowId ,
129
- Status : ciWorkflow .Status ,
130
- }, nil
131
- }
132
-
133
- func (impl * WorkflowStatusLatestServiceImpl ) GetCiWorkflowStatusLatestByAppId (appId int ) ([]* CiWorkflowStatusLatest , error ) {
134
- models , err := impl .workflowStatusLatestRepository .GetCiWorkflowStatusLatestByAppId (appId )
135
- if err != nil {
136
- impl .logger .Errorw ("error in getting ci workflow status latest by app id" , "err" , err , "appId" , appId )
137
- return nil , err
138
- }
139
-
140
- var result []* CiWorkflowStatusLatest
141
- for _ , model := range models {
142
- // Get status from ci_workflow table
143
- ciWorkflow , err := impl .ciWorkflowRepository .FindById (model .CiWorkflowId )
144
- if err != nil {
145
- impl .logger .Errorw ("error in getting ci workflow" , "err" , err , "ciWorkflowId" , model .CiWorkflowId )
146
- continue // Skip this entry if we can't get the workflow
147
- }
148
-
149
- result = append (result , & CiWorkflowStatusLatest {
150
- PipelineId : model .PipelineId ,
151
- AppId : model .AppId ,
152
- CiWorkflowId : model .CiWorkflowId ,
153
- Status : ciWorkflow .Status ,
154
- StorageConfigured : ciWorkflow .BlobStorageEnabled ,
155
- })
156
- }
157
-
158
- return result , nil
100
+ func (impl * WorkflowStatusLatestServiceImpl ) GetCiWorkflowStatusLatestByPipelineIds (pipelineIds []int ) ([]* pipelineConfig.CiWorkflowStatusLatest , error ) {
101
+ return impl .workflowStatusLatestRepository .GetCiWorkflowStatusLatestByPipelineIds (pipelineIds )
159
102
}
160
103
161
104
// CD Workflow Status Latest methods implementation
@@ -183,158 +126,6 @@ func (impl *WorkflowStatusLatestServiceImpl) SaveCdWorkflowStatusLatest(tx *pg.T
183
126
return impl .workflowStatusLatestRepository .SaveCdWorkflowStatusLatest (tx , model )
184
127
}
185
128
186
- func (impl * WorkflowStatusLatestServiceImpl ) GetCdWorkflowStatusLatestByPipelineIdAndWorkflowType (pipelineId int , workflowType string ) (* CdWorkflowStatusLatest , error ) {
187
- model , err := impl .workflowStatusLatestRepository .GetCdWorkflowStatusLatestByPipelineIdAndWorkflowType (nil , pipelineId , workflowType )
188
- if err != nil {
189
- if err == pg .ErrNoRows {
190
- // Fallback to old method
191
- return impl .getCdWorkflowStatusFromOldMethod (pipelineId , workflowType )
192
- }
193
- impl .logger .Errorw ("error in getting cd workflow status latest" , "err" , err , "pipelineId" , pipelineId , "workflowType" , workflowType )
194
- return nil , err
195
- }
196
-
197
- // Get status from cd_workflow_runner table
198
- cdWorkflowRunner , err := impl .cdWorkflowRepository .FindBasicWorkflowRunnerById (model .WorkflowRunnerId )
199
- if err != nil {
200
- impl .logger .Errorw ("error in getting cd workflow runner" , "err" , err , "workflowRunnerId" , model .WorkflowRunnerId )
201
- return nil , err
202
- }
203
-
204
- return & CdWorkflowStatusLatest {
205
- PipelineId : model .PipelineId ,
206
- AppId : model .AppId ,
207
- EnvironmentId : model .EnvironmentId ,
208
- WorkflowType : model .WorkflowType ,
209
- WorkflowRunnerId : model .WorkflowRunnerId ,
210
- Status : cdWorkflowRunner .Status ,
211
- }, nil
212
- }
213
-
214
- func (impl * WorkflowStatusLatestServiceImpl ) GetCdWorkflowStatusLatestByAppId (appId int ) ([]* CdWorkflowStatusLatest , error ) {
215
- models , err := impl .workflowStatusLatestRepository .GetCdWorkflowStatusLatestByAppId (appId )
216
- if err != nil {
217
- impl .logger .Errorw ("error in getting cd workflow status latest by app id" , "err" , err , "appId" , appId )
218
- return nil , err
219
- }
220
-
221
- var result []* CdWorkflowStatusLatest
222
- for _ , model := range models {
223
- // Get status from cd_workflow_runner table
224
- cdWorkflowRunner , err := impl .cdWorkflowRepository .FindBasicWorkflowRunnerById (model .WorkflowRunnerId )
225
- if err != nil {
226
- impl .logger .Errorw ("error in getting cd workflow runner" , "err" , err , "workflowRunnerId" , model .WorkflowRunnerId )
227
- continue // Skip this entry if we can't get the workflow runner
228
- }
229
-
230
- result = append (result , & CdWorkflowStatusLatest {
231
- PipelineId : model .PipelineId ,
232
- AppId : model .AppId ,
233
- EnvironmentId : model .EnvironmentId ,
234
- WorkflowType : model .WorkflowType ,
235
- WorkflowRunnerId : model .WorkflowRunnerId ,
236
- Status : cdWorkflowRunner .Status ,
237
- })
238
- }
239
-
240
- return result , nil
241
- }
242
-
243
- func (impl * WorkflowStatusLatestServiceImpl ) GetCdWorkflowStatusLatestByPipelineId (pipelineId int ) ([]* CdWorkflowStatusLatest , error ) {
244
- models , err := impl .workflowStatusLatestRepository .GetCdWorkflowStatusLatestByPipelineId (pipelineId )
245
- if err != nil {
246
- impl .logger .Errorw ("error in getting cd workflow status latest by pipeline id" , "err" , err , "pipelineId" , pipelineId )
247
- return nil , err
248
- }
249
-
250
- var result []* CdWorkflowStatusLatest
251
- for _ , model := range models {
252
- // Get status from cd_workflow_runner table
253
- cdWorkflowRunner , err := impl .cdWorkflowRepository .FindBasicWorkflowRunnerById (model .WorkflowRunnerId )
254
- if err != nil {
255
- impl .logger .Errorw ("error in getting cd workflow runner" , "err" , err , "workflowRunnerId" , model .WorkflowRunnerId )
256
- continue // Skip this entry if we can't get the workflow runner
257
- }
258
-
259
- result = append (result , & CdWorkflowStatusLatest {
260
- PipelineId : model .PipelineId ,
261
- AppId : model .AppId ,
262
- EnvironmentId : model .EnvironmentId ,
263
- WorkflowType : model .WorkflowType ,
264
- WorkflowRunnerId : model .WorkflowRunnerId ,
265
- Status : cdWorkflowRunner .Status ,
266
- })
267
- }
268
-
269
- return result , nil
270
- }
271
-
272
- // Fallback methods to old implementation when no entry found in latest status tables
273
- func (impl * WorkflowStatusLatestServiceImpl ) getCiWorkflowStatusFromOldMethod (pipelineId int ) (* CiWorkflowStatusLatest , error ) {
274
- // Get the latest CI workflow for this pipeline using the old method
275
- workflow , err := impl .ciWorkflowRepository .FindLastTriggeredWorkflow (pipelineId )
276
- if err != nil {
277
- if util2 .IsErrNoRows (err ) {
278
- return & CiWorkflowStatusLatest {
279
- PipelineId : pipelineId ,
280
- AppId : 0 , // Will need to be populated from pipeline info
281
- CiWorkflowId : 0 ,
282
- Status : "Not Triggered" ,
283
- }, nil
284
- }
285
- impl .logger .Errorw ("error in getting last triggered workflow" , "err" , err , "pipelineId" , pipelineId )
286
- return nil , err
287
- }
288
-
289
- return & CiWorkflowStatusLatest {
290
- PipelineId : pipelineId ,
291
- AppId : workflow .CiPipeline .AppId ,
292
- CiWorkflowId : workflow .Id ,
293
- Status : workflow .Status ,
294
- }, nil
295
- }
296
-
297
- func (impl * WorkflowStatusLatestServiceImpl ) getCdWorkflowStatusFromOldMethod (pipelineId int , workflowType string ) (* CdWorkflowStatusLatest , error ) {
298
- // Convert workflowType to the appropriate enum
299
- var runnerType bean.WorkflowType
300
- switch workflowType {
301
- case "PRE" :
302
- runnerType = bean .CD_WORKFLOW_TYPE_PRE
303
- case "DEPLOY" :
304
- runnerType = bean .CD_WORKFLOW_TYPE_DEPLOY
305
- case "POST" :
306
- runnerType = bean .CD_WORKFLOW_TYPE_POST
307
- default :
308
- runnerType = bean .WorkflowType (workflowType )
309
- }
310
-
311
- // Get the latest CD workflow runner for this pipeline and type using the old method
312
- wfr , err := impl .cdWorkflowRepository .FindLatestByPipelineIdAndRunnerType (pipelineId , runnerType )
313
- if err != nil {
314
- if err == pg .ErrNoRows {
315
- return & CdWorkflowStatusLatest {
316
- PipelineId : pipelineId ,
317
- AppId : 0 , // Will need to be populated from pipeline info
318
- EnvironmentId : 0 ,
319
- WorkflowType : workflowType ,
320
- WorkflowRunnerId : 0 ,
321
- Status : "Not Triggered" ,
322
- }, nil
323
- }
324
- impl .logger .Errorw ("error in getting latest cd workflow runner" , "err" , err , "pipelineId" , pipelineId , "runnerType" , runnerType )
325
- return nil , err
326
- }
327
-
328
- return & CdWorkflowStatusLatest {
329
- PipelineId : pipelineId ,
330
- AppId : wfr .CdWorkflow .Pipeline .AppId ,
331
- EnvironmentId : wfr .CdWorkflow .Pipeline .EnvironmentId ,
332
- WorkflowType : workflowType ,
333
- WorkflowRunnerId : wfr .Id ,
334
- Status : wfr .Status ,
335
- }, nil
336
- }
337
-
338
129
func (impl * WorkflowStatusLatestServiceImpl ) GetCdWorkflowLatestByPipelineIds (pipelineIds []int ) ([]* CdWorkflowStatusLatest , error ) {
339
130
cdWorkflowStatusLatest , err := impl .workflowStatusLatestRepository .GetCdWorkflowStatusLatestByPipelineIds (pipelineIds )
340
131
if err != nil {
0 commit comments