update aggregation logic
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:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -338,13 +339,18 @@ func ApplySQLiteTuning(ctx context.Context, dbConn *sqlx.DB) {
|
||||
return
|
||||
}
|
||||
// Best-effort pragmas; ignore errors to stay safe in constrained environments.
|
||||
var err error
|
||||
pragmas := []string{
|
||||
`PRAGMA journal_mode=WAL;`,
|
||||
`PRAGMA synchronous=NORMAL;`,
|
||||
`PRAGMA temp_store=MEMORY;`,
|
||||
`PRAGMA optimize;`,
|
||||
}
|
||||
for _, pragma := range pragmas {
|
||||
_, _ = dbConn.ExecContext(ctx, pragma)
|
||||
_, err = dbConn.ExecContext(ctx, pragma)
|
||||
if logger, ok := ctx.Value("logger").(*slog.Logger); ok && logger != nil {
|
||||
logger.Debug("Applied SQLite tuning pragma", "pragma", pragma, "error", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,8 @@ func (c *CronTask) RunVcenterDailyAggregate(ctx context.Context, logger *slog.Lo
|
||||
logger.Info("Daily summary job finished", "duration", time.Since(startedAt))
|
||||
}()
|
||||
targetTime := time.Now().Add(-time.Minute)
|
||||
return c.aggregateDailySummary(jobCtx, targetTime, false)
|
||||
// Always force regeneration on the scheduled run to refresh data even if a manual run happened earlier.
|
||||
return c.aggregateDailySummary(jobCtx, targetTime, true)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -872,9 +872,7 @@ func (c *CronTask) captureHourlySnapshotForVcenter(ctx context.Context, startTim
|
||||
presentByName := make(map[string]struct{}, len(vcVms))
|
||||
totals := snapshotTotals{}
|
||||
deletionsMarked := false
|
||||
progressEvery := 25
|
||||
nextLog := progressEvery
|
||||
for idx, vm := range vcVms {
|
||||
for _, vm := range vcVms {
|
||||
if strings.HasPrefix(vm.Name, "vCLS-") {
|
||||
continue
|
||||
}
|
||||
@@ -906,11 +904,6 @@ func (c *CronTask) captureHourlySnapshotForVcenter(ctx context.Context, startTim
|
||||
totals.VcpuTotal += nullInt64ToInt(row.VcpuCount)
|
||||
totals.RamTotal += nullInt64ToInt(row.RamGB)
|
||||
totals.DiskTotal += nullFloat64ToFloat(row.ProvisionedDisk)
|
||||
|
||||
if idx+1 >= nextLog {
|
||||
c.Logger.Debug("hourly snapshot progress", "processed", idx+1, "total", len(vcVms), "vcenter", url)
|
||||
nextLog += progressEvery
|
||||
}
|
||||
}
|
||||
c.Logger.Debug("hourly snapshot rows prepared", "vcenter", url, "rows", len(presentSnapshots))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user