Skip to content

Commit

Permalink
RHINENG-9452: add fatal errors for listener
Browse files Browse the repository at this point in the history
  • Loading branch information
psegedy committed Aug 16, 2024
1 parent 7db3e90 commit 9571534
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions listener/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,12 +449,12 @@ func storeOrUpdateSysPlatform(tx *gorm.DB, system *models.SystemPlatform, colsTo
if system.ID != 0 {
// update system
err := tx.Select(colsToUpdate).Updates(system).Error
return errors.Wrap(err, "unable to update system_platform")
return base.WrapFatalDBError(err, "unable to update system_platform")
}
// insert system
err := database.OnConflictUpdateMulti(tx, []string{"rh_account_id", "inventory_id"}, colsToUpdate...).
Save(system).Error
return errors.Wrap(err, "unable to insert to system_platform")
return base.WrapFatalDBError(err, "unable to insert to system_platform")
}

func getReporterID(reporter string) *int {
Expand Down Expand Up @@ -506,7 +506,10 @@ func ensureReposInDB(tx *gorm.DB, repos []string) (repoIDs []int64, added int64,
var existingRepos models.RepoSlice
err = tx.Model(&models.Repo{}).Where("name IN (?)", repos).Find(&existingRepos).Error
if err != nil {
return nil, 0, errors.Wrap(err, "unable to load repos")
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, 0, errors.Wrapf(err, "couldn't find repos: %s", repos)
}
return nil, 0, base.WrapFatalDBError(err, "unable to load repos")
}

inDBIDs := make(map[string]int64)
Expand All @@ -529,7 +532,7 @@ func ensureReposInDB(tx *gorm.DB, repos []string) (repoIDs []int64, added int64,
})
err = txOnConflict.Create(&toStore).Error
if err != nil {
return nil, 0, errors.Wrap(err, "unable to update repos")
return nil, 0, base.WrapFatalDBError(err, "unable to update repos")
}
added = txOnConflict.RowsAffected
for _, repo := range toStore {
Expand All @@ -553,13 +556,13 @@ func updateSystemRepos(tx *gorm.DB, rhAccountID int, systemID int64, repoIDs []i
})
err = database.BulkInsert(txOnConflict, repoSystemObjs)
if err != nil {
return 0, 0, errors.Wrap(err, "unable to update system repos")
return 0, 0, base.WrapFatalDBError(err, "unable to update system repos")
}
nAdded = txOnConflict.RowsAffected

nDeleted, err = deleteOtherSystemRepos(tx, rhAccountID, systemID, repoIDs)
if err != nil {
return nAdded, 0, errors.Wrap(err, "unable to delete out-of-date system repos")
return nAdded, 0, base.WrapFatalDBError(err, "unable to delete out-of-date system repos")
}

return nAdded, nDeleted, nil
Expand Down Expand Up @@ -702,7 +705,7 @@ func processUpload(host *Host, yumUpdates *YumUpdates) (*models.SystemPlatform,
var deleted models.DeletedSystem
if err := tx.Find(&deleted, "inventory_id = ?", host.ID).Error; err != nil &&
!errors.Is(err, gorm.ErrRecordNotFound) {
return nil, errors.Wrap(err, "Checking deleted systems")
return nil, base.WrapFatalDBError(err, "checking deleted systems")
}

// If the system was deleted in last hour, don't register this upload
Expand All @@ -716,7 +719,7 @@ func processUpload(host *Host, yumUpdates *YumUpdates) (*models.SystemPlatform,
}
err = tx.Commit().Error
if err != nil {
return nil, errors.Wrap(err, "Committing changes")
return nil, base.WrapFatalDBError(err, "committing changes")
}
return sys, nil
}
Expand Down

0 comments on commit 9571534

Please sign in to comment.