fix new-vm detection interval
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:
@@ -1104,23 +1104,16 @@ func (c *CronTask) compareWithPreviousSnapshot(
|
||||
c.Logger.Warn("failed to locate previous hourly snapshot for deletion comparison", "error", prevTableErr, "url", url)
|
||||
}
|
||||
|
||||
prevSnapshotTime := int64(0)
|
||||
if prevTableName != "" {
|
||||
if suffix := strings.TrimPrefix(prevTableName, "inventory_hourly_"); suffix != prevTableName {
|
||||
if ts, err := strconv.ParseInt(suffix, 10, 64); err == nil {
|
||||
prevSnapshotTime = ts
|
||||
}
|
||||
}
|
||||
}
|
||||
prevSnapshotTime, _ := parseSnapshotTime(prevTableName)
|
||||
|
||||
newCount := 0
|
||||
if prevTableName != "" {
|
||||
moreMissing := c.markMissingFromPrevious(ctx, dbConn, prevTableName, url, startTime, presentSnapshots, presentByUuid, presentByName, inventoryByVmID, inventoryByUuid, inventoryByName)
|
||||
missingCount += moreMissing
|
||||
expectedSeconds := int64(durationFromSeconds(c.Settings.Values.Settings.VcenterInventorySnapshotSeconds, time.Hour).Seconds())
|
||||
// Allow runs as soon as half the normal interval; treat larger gaps as unreliable for "new" detection.
|
||||
if HasSnapshotGap(prevSnapshotTime, startTime.Unix(), expectedSeconds/2) {
|
||||
c.Logger.Info("skipping new-VM detection due to gap between snapshots", "prev_table", prevTableName, "prev_snapshot_unix", prevSnapshotTime, "current_snapshot_unix", startTime.Unix())
|
||||
// Skip only if snapshots are much closer together than the configured cadence (e.g., rerun inside half interval).
|
||||
if SnapshotTooSoon(prevSnapshotTime, startTime.Unix(), expectedSeconds) {
|
||||
c.Logger.Info("skipping new-VM detection because snapshots are too close together", "prev_table", prevTableName, "prev_snapshot_unix", prevSnapshotTime, "current_snapshot_unix", startTime.Unix(), "expected_interval_seconds", expectedSeconds)
|
||||
} else {
|
||||
newCount = countNewFromPrevious(ctx, dbConn, prevTableName, url, presentSnapshots)
|
||||
if newCount > 0 {
|
||||
|
||||
Reference in New Issue
Block a user