@@ -204,39 +204,20 @@ func (impl GitWatcherImpl) handleSshKeyCreationAndRetry(gitCtx GitContext, mater
204
204
impl .logger .Info ("Retrying fetching for" , "repo" , material .Url )
205
205
updated , repo , errMsg , err = impl .FetchAndUpdateMaterial (gitCtx , material , location )
206
206
if err != nil {
207
- impl .logAndUpdateDbError (material .Id , errMsg )
208
207
impl .logger .Errorw ("error in fetching material details in retry" , "repo" , material .Url , "err" , err )
208
+ errorMessage := util2 .BuildDisplayErrorMessage (errMsg , err )
209
+ material .FetchStatus = false
210
+ material .FetchErrorMessage = errorMessage
209
211
return false , nil , errMsg , err
210
212
}
211
213
}
212
214
return updated , repo , errMsg , err
213
215
}
214
216
215
- // Helper function to log and update database with error message for CI pipeline material
216
- func (impl GitWatcherImpl ) logAndUpdateDbError (materialId int , errMsg string ) {
217
- dbErr := impl .ciPipelineMaterialRepository .UpdateMaterialsErroredForGitMaterialId (materialId , sql .SOURCE_TYPE_BRANCH_FIXED , errMsg )
218
- if dbErr != nil {
219
- // made this non-blocking
220
- impl .logger .Errorw ("error encountered in updating ci pipeline material" , "materialId" , materialId , "dbErr" , dbErr )
221
- }
222
- }
223
-
224
- func (impl GitWatcherImpl ) logAndUpdateDbNonError (materialId int , fetchStatus bool ) {
225
- if ! fetchStatus {
226
- // if fetch previously failed then update errored to false
227
- dbErr := impl .ciPipelineMaterialRepository .UpdateMaterialsNonErroredForGitMaterialId (materialId , sql .SOURCE_TYPE_BRANCH_FIXED )
228
- if dbErr != nil {
229
- // made this non-blocking
230
- impl .logger .Errorw ("error encountered in updating ci pipeline material" , "materialId" , materialId , "dbErr" , dbErr )
231
- }
232
- }
233
- }
234
-
235
217
func (impl GitWatcherImpl ) pollGitMaterialAndNotify (material * sql.GitMaterial ) (string , error ) {
236
218
gitProvider := material .GitProvider
237
219
userName , password , err := GetUserNamePassword (gitProvider )
238
220
location := material .CheckoutLocation
239
- initialFetchStatus := material .FetchStatus
240
221
if err != nil {
241
222
impl .logger .Errorw ("error in determining location" , "url" , material .Url , "err" , err )
242
223
return "" , err
@@ -258,14 +239,15 @@ func (impl GitWatcherImpl) pollGitMaterialAndNotify(material *sql.GitMaterial) (
258
239
}
259
240
} else {
260
241
// Log and update database if retry not possible or SSH key already exists
261
- impl .logAndUpdateDbError (material .Id , errMsg )
242
+ impl .logger .Errorw ("error in fetching material details in retry" , "repo" , material .Url , "materialId" , material .Id , "err" , err , "errMsg" , errMsg )
243
+ errorMessage := util2 .BuildDisplayErrorMessage (errMsg , err )
244
+ material .FetchStatus = false
245
+ material .FetchErrorMessage = errorMessage
262
246
return errMsg , err
263
247
}
264
248
}
265
249
if ! updated {
266
250
impl .logger .Debugw ("no new commit found but fetch success" , "url" , material .Url , "fetchStatus" , material .FetchStatus )
267
- // update set errored false in ci pipeline material as fetch is successful
268
- impl .logAndUpdateDbNonError (material .Id , initialFetchStatus )
269
251
return "" , nil
270
252
}
271
253
materials , err := impl .ciPipelineMaterialRepository .FindByGitMaterialId (material .Id )
@@ -336,22 +318,21 @@ func (impl GitWatcherImpl) pollGitMaterialAndNotify(material *sql.GitMaterial) (
336
318
updatedMaterialsModel = append (updatedMaterialsModel , material )
337
319
}
338
320
}
339
- if len (updatedMaterialsModel ) > 0 {
340
- err = impl .NotifyForMaterialUpdate (updatedMaterials , material )
341
- if err != nil {
342
- impl .logger .Errorw ("error in sending notification for materials" , "url" , material .Url , "update" , updatedMaterialsModel )
343
- }
344
- err = impl .ciPipelineMaterialRepository .Update (updatedMaterialsModel )
321
+ if len (erroredMaterialsModels ) > 0 {
322
+ err = impl .ciPipelineMaterialRepository .Update (erroredMaterialsModels )
345
323
if err != nil {
346
- impl .logger .Errorw ("error in update db " , "url" , material .Url , "update" , updatedMaterialsModel )
347
- impl .logger .Errorw ("error in sending notification for materials" , "url" , material .Url , "update" , updatedMaterialsModel )
324
+ impl .logger .Errorw ("error in update db " , "url" , material .Url , "update" , erroredMaterialsModels )
348
325
}
349
326
}
350
- if len (erroredMaterialsModels ) > 0 {
327
+ if len (updatedMaterialsModel ) > 0 {
351
328
err = impl .ciPipelineMaterialRepository .Update (updatedMaterialsModel )
352
329
if err != nil {
353
330
impl .logger .Errorw ("error in update db " , "url" , material .Url , "update" , updatedMaterialsModel )
354
- impl .logger .Errorw ("error in sending notification for materials" , "url" , material .Url , "update" , updatedMaterialsModel )
331
+ } else {
332
+ err = impl .NotifyForMaterialUpdate (updatedMaterials , material )
333
+ if err != nil {
334
+ impl .logger .Errorw ("error in sending notification for materials" , "url" , material .Url , "update" , updatedMaterialsModel )
335
+ }
355
336
}
356
337
}
357
338
return "" , nil
0 commit comments