fix postgres code path
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -12,7 +12,6 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
"vctp/db"
|
"vctp/db"
|
||||||
"vctp/db/queries"
|
|
||||||
"vctp/internal/metrics"
|
"vctp/internal/metrics"
|
||||||
"vctp/internal/report"
|
"vctp/internal/report"
|
||||||
)
|
)
|
||||||
@@ -559,7 +558,6 @@ WHERE "Vcenter" = ? AND "DeletedAt" IS NOT NULL AND "DeletedAt" > 0 AND "Deleted
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *CronTask) applyInventoryDeletions(ctx context.Context, agg map[dailyAggKey]*dailyAggVal, start, end time.Time) int {
|
func (c *CronTask) applyInventoryDeletions(ctx context.Context, agg map[dailyAggKey]*dailyAggVal, start, end time.Time) int {
|
||||||
dbConn := c.Database.DB()
|
|
||||||
vcenters := make(map[string]struct{}, 8)
|
vcenters := make(map[string]struct{}, 8)
|
||||||
for k := range agg {
|
for k := range agg {
|
||||||
if k.Vcenter != "" {
|
if k.Vcenter != "" {
|
||||||
@@ -568,7 +566,7 @@ func (c *CronTask) applyInventoryDeletions(ctx context.Context, agg map[dailyAgg
|
|||||||
}
|
}
|
||||||
totalApplied := 0
|
totalApplied := 0
|
||||||
for vcenter := range vcenters {
|
for vcenter := range vcenters {
|
||||||
inventoryRows, err := queries.New(dbConn).GetInventoryByVcenter(ctx, vcenter)
|
inventoryRows, err := c.Database.Queries().GetInventoryByVcenter(ctx, vcenter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Logger.Warn("failed to load inventory for daily deletion times", "vcenter", vcenter, "error", err)
|
c.Logger.Warn("failed to load inventory for daily deletion times", "vcenter", vcenter, "error", err)
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -840,8 +840,8 @@ func snapshotFromInventory(inv queries.Inventory, snapshotTime time.Time) Invent
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadInventoryMaps(ctx context.Context, dbConn *sqlx.DB, url string) ([]queries.Inventory, map[string]queries.Inventory, map[string]queries.Inventory, map[string]queries.Inventory, error) {
|
func loadInventoryMaps(ctx context.Context, querier db.Querier, url string) ([]queries.Inventory, map[string]queries.Inventory, map[string]queries.Inventory, map[string]queries.Inventory, error) {
|
||||||
inventoryRows, err := queries.New(dbConn).GetInventoryByVcenter(ctx, url)
|
inventoryRows, err := querier.GetInventoryByVcenter(ctx, url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, nil, nil, fmt.Errorf("unable to query inventory table: %w", err)
|
return nil, nil, nil, nil, fmt.Errorf("unable to query inventory table: %w", err)
|
||||||
}
|
}
|
||||||
@@ -862,7 +862,7 @@ func loadInventoryMaps(ctx context.Context, dbConn *sqlx.DB, url string) ([]quer
|
|||||||
return inventoryRows, inventoryByVmID, inventoryByUuid, inventoryByName, nil
|
return inventoryRows, inventoryByVmID, inventoryByUuid, inventoryByName, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func prepareDeletionCandidates(ctx context.Context, log *slog.Logger, dbConn *sqlx.DB, url string, inventoryRows []queries.Inventory,
|
func prepareDeletionCandidates(ctx context.Context, log *slog.Logger, dbConn *sqlx.DB, querier db.Querier, url string, inventoryRows []queries.Inventory,
|
||||||
presentSnapshots map[string]InventorySnapshotRow, presentByUuid, presentByName map[string]struct{}, startTime time.Time) (int, bool, []deletionCandidate) {
|
presentSnapshots map[string]InventorySnapshotRow, presentByUuid, presentByName map[string]struct{}, startTime time.Time) (int, bool, []deletionCandidate) {
|
||||||
candidates := make([]deletionCandidate, 0)
|
candidates := make([]deletionCandidate, 0)
|
||||||
missingCount := 0
|
missingCount := 0
|
||||||
@@ -904,7 +904,7 @@ func prepareDeletionCandidates(ctx context.Context, log *slog.Logger, dbConn *sq
|
|||||||
if !row.DeletionTime.Valid {
|
if !row.DeletionTime.Valid {
|
||||||
deletionTime := startTime.Unix()
|
deletionTime := startTime.Unix()
|
||||||
row.DeletionTime = sql.NullInt64{Int64: deletionTime, Valid: true}
|
row.DeletionTime = sql.NullInt64{Int64: deletionTime, Valid: true}
|
||||||
if err := queries.New(dbConn).InventoryMarkDeleted(ctx, queries.InventoryMarkDeletedParams{
|
if err := querier.InventoryMarkDeleted(ctx, queries.InventoryMarkDeletedParams{
|
||||||
DeletionTime: row.DeletionTime,
|
DeletionTime: row.DeletionTime,
|
||||||
VmId: inv.VmId,
|
VmId: inv.VmId,
|
||||||
DatacenterName: inv.Datacenter,
|
DatacenterName: inv.Datacenter,
|
||||||
@@ -1070,7 +1070,8 @@ func (c *CronTask) captureHourlySnapshotForVcenter(ctx context.Context, startTim
|
|||||||
folderLookup := resources.folderLookup
|
folderLookup := resources.folderLookup
|
||||||
rpLookup := resources.rpLookup
|
rpLookup := resources.rpLookup
|
||||||
|
|
||||||
inventoryRows, inventoryByVmID, inventoryByUuid, inventoryByName, err := loadInventoryMaps(ctx, c.Database.DB(), url)
|
q := c.Database.Queries()
|
||||||
|
inventoryRows, inventoryByVmID, inventoryByUuid, inventoryByName, err := loadInventoryMaps(ctx, q, url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -1093,7 +1094,7 @@ func (c *CronTask) captureHourlySnapshotForVcenter(ctx context.Context, startTim
|
|||||||
}
|
}
|
||||||
log.Debug("checking inventory for missing VMs")
|
log.Debug("checking inventory for missing VMs")
|
||||||
|
|
||||||
missingCount, deletionsMarked, candidates := prepareDeletionCandidates(ctx, log, dbConn, url, inventoryRows, presentSnapshots, presentByUuid, presentByName, startTime)
|
missingCount, deletionsMarked, candidates := prepareDeletionCandidates(ctx, log, dbConn, q, url, inventoryRows, presentSnapshots, presentByUuid, presentByName, startTime)
|
||||||
newCount := 0
|
newCount := 0
|
||||||
prevTableName := ""
|
prevTableName := ""
|
||||||
reportTables := make(map[string]struct{})
|
reportTables := make(map[string]struct{})
|
||||||
|
|||||||
Reference in New Issue
Block a user