-
Notifications
You must be signed in to change notification settings - Fork 48
feat: add account_advisory cleanup to advisory cleanup job #2290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| package cleaning | ||
|
|
||
| import ( | ||
| "app/base/core" | ||
| "app/base/models" | ||
| "app/base/utils" | ||
| "app/tasks" | ||
| "sync" | ||
| ) | ||
|
|
||
| func RunCleanAccountAdvisory() { | ||
| tasks.HandleContextCancel(tasks.WaitAndExit) | ||
| core.ConfigureApp() | ||
| defer utils.LogPanics(true) | ||
|
|
||
| var wg sync.WaitGroup | ||
| var aadErr, aaErr error | ||
| wg.Add(2) | ||
|
|
||
| go func() { | ||
| defer wg.Done() | ||
| utils.LogInfo("Deleting advisory rows with 0 applicable/installable systems from advisory_account_data") | ||
| aadErr = CleanAdvisoryAccountData() | ||
| if aadErr != nil { | ||
| utils.LogError("err", aadErr, "Cleaning advisory_account_data") | ||
| } | ||
| }() | ||
|
|
||
| go func() { | ||
| defer wg.Done() | ||
| utils.LogInfo("Deleting advisory rows with 0 applicable/installable systems from account_advisory") | ||
| aaErr = CleanAccountAdvisory() | ||
| if aaErr != nil { | ||
| utils.LogError("err", aaErr, "Cleaning account_advisory") | ||
| } | ||
| }() | ||
|
|
||
| wg.Wait() | ||
| if aadErr != nil || aaErr != nil { | ||
| utils.LogWarn("RunCleanAccountAdvisory task completed with errors") | ||
| } else { | ||
| utils.LogInfo("RunCleanAccountAdvisory task performed successfully") | ||
| } | ||
| } | ||
|
|
||
| func CleanAdvisoryAccountData() error { | ||
| tx := tasks.CancelableDB().Begin() | ||
| defer tx.Rollback() | ||
|
|
||
| result := tx.Delete(&models.AdvisoryAccountData{}, "systems_installable <= 0 AND systems_applicable <= 0") | ||
| if result.Error != nil { | ||
| return result.Error | ||
| } | ||
|
|
||
| tx.Commit() | ||
|
Comment on lines
+46
to
+55
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (bug_risk): Avoid deferring Rollback after a successful Commit and check Commit errors With Prefer an explicit pattern that:
For example: func CleanAdvisoryAccountData() error {
tx := tasks.CancelableDB().Begin()
if tx.Error != nil {
return tx.Error
}
defer func() {
if r := recover(); r != nil {
tx.Rollback()
panic(r)
}
}()
result := tx.Delete(&models.AdvisoryAccountData{}, "systems_installable <= 0 AND systems_applicable <= 0")
if result.Error != nil {
tx.Rollback()
return result.Error
}
if err := tx.Commit().Error; err != nil {
return err
}
utils.LogInfo("nDeleted", result.RowsAffected, "advisory_account_data cleaned successfully")
return nil
}Same fix applies to |
||
| utils.LogInfo("nDeleted", result.RowsAffected, "advisory_account_data cleaned successfully") | ||
| return nil | ||
| } | ||
|
|
||
| func CleanAccountAdvisory() error { | ||
| tx := tasks.CancelableDB().Begin() | ||
| defer tx.Rollback() | ||
|
|
||
| result := tx.Delete(&models.AccountAdvisory{}, "systems_installable <= 0 AND systems_applicable <= 0") | ||
| if result.Error != nil { | ||
| return result.Error | ||
| } | ||
|
|
||
| tx.Commit() | ||
| utils.LogInfo("nDeleted", result.RowsAffected, "account_advisory cleaned successfully") | ||
| return nil | ||
| } | ||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.