update aggregation jobs
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:
@@ -317,6 +317,13 @@ func (c *CronTask) RunSnapshotCleanup(ctx context.Context, logger *slog.Logger)
|
||||
|
||||
hourlyCutoff := now.AddDate(0, 0, -hourlyMaxDays)
|
||||
dailyCutoff := now.AddDate(0, -dailyMaxMonths, 0)
|
||||
logger.Info("Starting snapshot cleanup",
|
||||
"now", now,
|
||||
"hourly_cutoff", truncateDate(hourlyCutoff),
|
||||
"daily_cutoff", truncateDate(dailyCutoff),
|
||||
"hourly_max_age_days", hourlyMaxDays,
|
||||
"daily_max_age_months", dailyMaxMonths,
|
||||
)
|
||||
|
||||
dbConn := c.Database.DB()
|
||||
|
||||
@@ -324,8 +331,10 @@ func (c *CronTask) RunSnapshotCleanup(ctx context.Context, logger *slog.Logger)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
logger.Info("Snapshot cleanup hourly scan", "tables_found", len(hourlyTables))
|
||||
|
||||
removedHourly := 0
|
||||
scannedHourly := 0
|
||||
for _, table := range hourlyTables {
|
||||
if strings.HasPrefix(table, "inventory_daily_summary_") {
|
||||
continue
|
||||
@@ -334,6 +343,7 @@ func (c *CronTask) RunSnapshotCleanup(ctx context.Context, logger *slog.Logger)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
scannedHourly++
|
||||
if tableDate.Before(truncateDate(hourlyCutoff)) {
|
||||
if err := dropSnapshotTable(ctx, dbConn, table); err != nil {
|
||||
c.Logger.Error("failed to drop hourly snapshot table", "error", err, "table", table)
|
||||
@@ -350,12 +360,15 @@ func (c *CronTask) RunSnapshotCleanup(ctx context.Context, logger *slog.Logger)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
logger.Info("Snapshot cleanup daily scan", "tables_found", len(dailyTables))
|
||||
removedDaily := 0
|
||||
scannedDaily := 0
|
||||
for _, table := range dailyTables {
|
||||
tableDate, ok := parseSnapshotDate(table, "inventory_daily_summary_", "20060102")
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
scannedDaily++
|
||||
if tableDate.Before(truncateDate(dailyCutoff)) {
|
||||
if err := dropSnapshotTable(ctx, dbConn, table); err != nil {
|
||||
c.Logger.Error("failed to drop daily snapshot table", "error", err, "table", table)
|
||||
@@ -369,6 +382,8 @@ func (c *CronTask) RunSnapshotCleanup(ctx context.Context, logger *slog.Logger)
|
||||
}
|
||||
|
||||
c.Logger.Info("Finished snapshot cleanup",
|
||||
"hourly_tables_scanned", scannedHourly,
|
||||
"daily_tables_scanned", scannedDaily,
|
||||
"removed_hourly_tables", removedHourly,
|
||||
"removed_daily_tables", removedDaily,
|
||||
"hourly_max_age_days", hourlyMaxDays,
|
||||
|
||||
Reference in New Issue
Block a user