This commit is contained in:
@@ -169,7 +169,11 @@ func MigrateSnapshotRegistry(ctx context.Context, database db.Database) (Snapsho
|
||||
}
|
||||
if snapshotTime.IsZero() {
|
||||
suffix := strings.TrimPrefix(table, "inventory_hourly_")
|
||||
if parsed, parseErr := time.Parse("2006010215", suffix); parseErr == nil {
|
||||
if parsed, parseErr := time.Parse("200601021504", suffix); parseErr == nil {
|
||||
// Name encoded with date+hour+minute (e.g., 15-minute cadence)
|
||||
snapshotTime = parsed
|
||||
} else if parsed, parseErr := time.Parse("2006010215", suffix); parseErr == nil {
|
||||
// Legacy hour-only encoding
|
||||
snapshotTime = parsed
|
||||
} else if epoch, parseErr := strconv.ParseInt(suffix, 10, 64); parseErr == nil {
|
||||
snapshotTime = time.Unix(epoch, 0)
|
||||
|
||||
17
main.go
17
main.go
@@ -184,10 +184,7 @@ func main() {
|
||||
cronAggregateFrequency = durationFromSeconds(s.Values.Settings.VcenterInventoryAggregateSeconds, 86400)
|
||||
logger.Debug("Setting VM inventory daily aggregation cronjob frequency to", "frequency", cronAggregateFrequency)
|
||||
|
||||
startsAt3 := time.Now().Add(cronSnapshotFrequency)
|
||||
if cronSnapshotFrequency == time.Hour {
|
||||
startsAt3 = time.Now().Truncate(time.Hour).Add(time.Hour)
|
||||
}
|
||||
startsAt3 := alignStart(time.Now(), cronSnapshotFrequency)
|
||||
job3, err := c.NewJob(
|
||||
gocron.DurationJob(cronSnapshotFrequency),
|
||||
gocron.NewTask(func() {
|
||||
@@ -296,6 +293,18 @@ func main() {
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
// alignStart snaps the first run to a sensible boundary (hour or 15-minute block) when possible.
|
||||
func alignStart(now time.Time, freq time.Duration) time.Time {
|
||||
if freq == time.Hour {
|
||||
return now.Truncate(time.Hour).Add(time.Hour)
|
||||
}
|
||||
quarter := 15 * time.Minute
|
||||
if freq%quarter == 0 {
|
||||
return now.Truncate(quarter).Add(quarter)
|
||||
}
|
||||
return now.Add(freq)
|
||||
}
|
||||
|
||||
func durationFromSeconds(value int, fallback int) time.Duration {
|
||||
if value <= 0 {
|
||||
return time.Second * time.Duration(fallback)
|
||||
|
||||
Reference in New Issue
Block a user