@@ -30,7 +30,7 @@ import (
30
30
31
31
type WorkflowStatusLatestService interface {
32
32
// CI Workflow Status Latest methods
33
- SaveCiWorkflowStatusLatest (tx * pg.Tx , pipelineId , ciWorkflowId int , userId int32 ) error
33
+ SaveCiWorkflowStatusLatest (tx * pg.Tx , pipelineId , appId , ciWorkflowId int , userId int32 ) error
34
34
GetCiWorkflowStatusLatestByPipelineId (pipelineId int ) (* CiWorkflowStatusLatest , error )
35
35
GetCiWorkflowStatusLatestByAppId (appId int ) ([]* CiWorkflowStatusLatest , error )
36
36
@@ -83,53 +83,25 @@ type CdWorkflowStatusLatest struct {
83
83
Status string `json:"status"` // Derived from cd_workflow_runner table
84
84
}
85
85
86
- func (impl * WorkflowStatusLatestServiceImpl ) SaveCiWorkflowStatusLatest (tx * pg.Tx , pipelineId , ciWorkflowId int , userId int32 ) error {
86
+ func (impl * WorkflowStatusLatestServiceImpl ) SaveCiWorkflowStatusLatest (tx * pg.Tx , pipelineId , appId , ciWorkflowId int , userId int32 ) error {
87
87
// Validate required parameters
88
- if pipelineId <= 0 {
89
- impl .logger .Errorw ("invalid pipelineId provided" , "pipelineId" , pipelineId )
90
- return fmt .Errorf ("invalid pipelineId: %d" , pipelineId )
91
- }
92
-
93
88
if ciWorkflowId <= 0 {
94
89
impl .logger .Errorw ("invalid ciWorkflowId provided" , "ciWorkflowId" , ciWorkflowId )
95
90
return fmt .Errorf ("invalid ciWorkflowId: %d" , ciWorkflowId )
96
91
}
97
- ciPipeline , err := impl .ciPipelineRepository .FindOneWithAppData (pipelineId )
98
- if err != nil {
99
- impl .logger .Errorw ("error in fetching ci pipeline for appId" , "ciPipelineId" , pipelineId , "err" , err )
100
- return err
101
- }
102
- appId := ciPipeline .AppId
103
-
104
- // Check if entry exists
105
- existingEntry , err := impl .workflowStatusLatestRepository .GetCiWorkflowStatusLatestByPipelineId (pipelineId )
106
- if err != nil && ! util2 .IsErrNoRows (err ) {
107
- impl .logger .Errorw ("error in getting ci workflow status latest" , "err" , err , "pipelineId" , pipelineId )
108
- return err
109
- }
110
92
111
93
now := time .Now ()
112
- if util2 .IsErrNoRows (err ) {
113
- // Create new entry
114
- model := & pipelineConfig.CiWorkflowStatusLatest {
115
- PipelineId : pipelineId ,
116
- AppId : appId ,
117
- CiWorkflowId : ciWorkflowId ,
118
- }
119
- model .CreatedBy = userId
120
- model .CreatedOn = now
121
- model .UpdatedBy = userId
122
- model .UpdatedOn = now
123
-
124
- return impl .workflowStatusLatestRepository .SaveCiWorkflowStatusLatest (tx , model )
125
- } else {
126
- // Update existing entry
127
- existingEntry .CiWorkflowId = ciWorkflowId
128
- existingEntry .UpdatedBy = userId
129
- existingEntry .UpdatedOn = now
130
-
131
- return impl .workflowStatusLatestRepository .UpdateCiWorkflowStatusLatest (tx , existingEntry )
94
+ model := & pipelineConfig.CiWorkflowStatusLatest {
95
+ PipelineId : pipelineId ,
96
+ AppId : appId ,
97
+ CiWorkflowId : ciWorkflowId ,
132
98
}
99
+ model .CreatedBy = userId
100
+ model .CreatedOn = now
101
+ model .UpdatedBy = userId
102
+ model .UpdatedOn = now
103
+
104
+ return impl .workflowStatusLatestRepository .SaveCiWorkflowStatusLatest (tx , model )
133
105
}
134
106
135
107
func (impl * WorkflowStatusLatestServiceImpl ) GetCiWorkflowStatusLatestByPipelineId (pipelineId int ) (* CiWorkflowStatusLatest , error ) {
@@ -189,91 +161,26 @@ func (impl *WorkflowStatusLatestServiceImpl) GetCiWorkflowStatusLatestByAppId(ap
189
161
// CD Workflow Status Latest methods implementation
190
162
func (impl * WorkflowStatusLatestServiceImpl ) SaveCdWorkflowStatusLatest (tx * pg.Tx , pipelineId , appId , environmentId , workflowRunnerId int , workflowType string , userId int32 ) error {
191
163
// Validate required parameters
192
- if pipelineId <= 0 {
193
- impl .logger .Errorw ("invalid pipelineId provided" , "pipelineId" , pipelineId )
194
- return fmt .Errorf ("invalid pipelineId: %d" , pipelineId )
195
- }
196
-
197
164
if workflowRunnerId <= 0 {
198
165
impl .logger .Errorw ("invalid workflowRunnerId provided" , "workflowRunnerId" , workflowRunnerId )
199
166
return fmt .Errorf ("invalid workflowRunnerId: %d" , workflowRunnerId )
200
167
}
201
168
202
- // If appId or environmentId is not provided (0), fetch them from the CdWorkflow
203
- if appId <= 0 || environmentId <= 0 {
204
- cdWorkflowRunner , err := impl .cdWorkflowRepository .FindBasicWorkflowRunnerById (workflowRunnerId )
205
- if err != nil {
206
- impl .logger .Errorw ("error in fetching cd workflow runner to get appId/environmentId" , "err" , err , "workflowRunnerId" , workflowRunnerId )
207
- return err
208
- }
209
-
210
- if cdWorkflowRunner == nil {
211
- impl .logger .Errorw ("cd workflow runner not found" , "workflowRunnerId" , workflowRunnerId )
212
- return fmt .Errorf ("cd workflow runner not found with id: %d" , workflowRunnerId )
213
- }
214
-
215
- // Check if CdWorkflow is loaded
216
- if cdWorkflowRunner .CdWorkflow == nil {
217
- impl .logger .Errorw ("cd workflow not loaded in cd workflow runner" , "workflowRunnerId" , workflowRunnerId , "cdWorkflowId" , cdWorkflowRunner .CdWorkflowId )
218
- return fmt .Errorf ("cd workflow not loaded for workflow runner id: %d" , workflowRunnerId )
219
- }
220
-
221
- // Check if Pipeline is loaded
222
- if cdWorkflowRunner .CdWorkflow .Pipeline == nil {
223
- impl .logger .Errorw ("pipeline not loaded in cd workflow" , "workflowRunnerId" , workflowRunnerId , "cdWorkflowId" , cdWorkflowRunner .CdWorkflowId , "pipelineId" , cdWorkflowRunner .CdWorkflow .PipelineId )
224
- return fmt .Errorf ("pipeline not loaded for workflow runner id: %d" , workflowRunnerId )
225
- }
226
-
227
- if appId <= 0 {
228
- appId = cdWorkflowRunner .CdWorkflow .Pipeline .AppId
229
- if appId <= 0 {
230
- impl .logger .Errorw ("invalid appId in pipeline" , "workflowRunnerId" , workflowRunnerId , "pipelineId" , cdWorkflowRunner .CdWorkflow .PipelineId , "appId" , appId )
231
- return fmt .Errorf ("invalid appId in pipeline: %d" , appId )
232
- }
233
- impl .logger .Debugw ("fetched appId from cd workflow runner" , "workflowRunnerId" , workflowRunnerId , "appId" , appId )
234
- }
235
-
236
- if environmentId <= 0 {
237
- environmentId = cdWorkflowRunner .CdWorkflow .Pipeline .EnvironmentId
238
- if environmentId <= 0 {
239
- impl .logger .Errorw ("invalid environmentId in pipeline" , "workflowRunnerId" , workflowRunnerId , "pipelineId" , cdWorkflowRunner .CdWorkflow .PipelineId , "environmentId" , environmentId )
240
- return fmt .Errorf ("invalid environmentId in pipeline: %d" , environmentId )
241
- }
242
- impl .logger .Debugw ("fetched environmentId from cd workflow runner" , "workflowRunnerId" , workflowRunnerId , "environmentId" , environmentId )
243
- }
244
- }
245
-
246
- // Check if entry exists
247
- existingEntry , err := impl .workflowStatusLatestRepository .GetCdWorkflowStatusLatestByPipelineIdAndWorkflowType (tx , pipelineId , workflowType )
248
- if err != nil && err != pg .ErrNoRows {
249
- impl .logger .Errorw ("error in getting cd workflow status latest" , "err" , err , "pipelineId" , pipelineId , "workflowType" , workflowType )
250
- return err
251
- }
252
-
169
+ // Create new entry (always save, don't update)
253
170
now := time .Now ()
254
- if err == pg .ErrNoRows {
255
- // Create new entry
256
- model := & pipelineConfig.CdWorkflowStatusLatest {
257
- PipelineId : pipelineId ,
258
- AppId : appId ,
259
- EnvironmentId : environmentId ,
260
- WorkflowType : workflowType ,
261
- WorkflowRunnerId : workflowRunnerId ,
262
- }
263
- model .CreatedBy = userId
264
- model .CreatedOn = now
265
- model .UpdatedBy = userId
266
- model .UpdatedOn = now
267
-
268
- return impl .workflowStatusLatestRepository .SaveCdWorkflowStatusLatest (tx , model )
269
- } else {
270
- // Update existing entry
271
- existingEntry .WorkflowRunnerId = workflowRunnerId
272
- existingEntry .UpdatedBy = userId
273
- existingEntry .UpdatedOn = now
274
-
275
- return impl .workflowStatusLatestRepository .UpdateCdWorkflowStatusLatest (tx , existingEntry )
171
+ model := & pipelineConfig.CdWorkflowStatusLatest {
172
+ PipelineId : pipelineId ,
173
+ AppId : appId ,
174
+ EnvironmentId : environmentId ,
175
+ WorkflowType : workflowType ,
176
+ WorkflowRunnerId : workflowRunnerId ,
276
177
}
178
+ model .CreatedBy = userId
179
+ model .CreatedOn = now
180
+ model .UpdatedBy = userId
181
+ model .UpdatedOn = now
182
+
183
+ return impl .workflowStatusLatestRepository .SaveCdWorkflowStatusLatest (tx , model )
277
184
}
278
185
279
186
func (impl * WorkflowStatusLatestServiceImpl ) GetCdWorkflowStatusLatestByPipelineIdAndWorkflowType (pipelineId int , workflowType string ) (* CdWorkflowStatusLatest , error ) {
0 commit comments