ensure we dont collect hourly snapshot too soon after startup
Some checks failed
continuous-integration/drone/push Build was killed
Some checks failed
continuous-integration/drone/push Build was killed
This commit is contained in:
@@ -51,6 +51,30 @@ func (c *CronTask) RunVcenterSnapshotHourly(ctx context.Context, logger *slog.Lo
|
||||
logger.Info("Hourly snapshot job finished", "duration", time.Since(startedAt))
|
||||
}()
|
||||
startTime := time.Now()
|
||||
|
||||
// reload settings in case vcenter list has changed
|
||||
c.Settings.ReadYMLSettings()
|
||||
|
||||
if c.FirstHourlySnapshotCheck {
|
||||
if err := report.EnsureSnapshotRegistry(ctx, c.Database); err != nil {
|
||||
return err
|
||||
}
|
||||
lastSnapshot, err := report.LatestSnapshotTime(ctx, c.Database, "hourly")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
minIntervalSeconds := intWithDefault(c.Settings.Values.Settings.VcenterInventorySnapshotSeconds, 3600)
|
||||
if !lastSnapshot.IsZero() && startTime.Sub(lastSnapshot) < time.Duration(minIntervalSeconds)*time.Second {
|
||||
c.Logger.Info("Skipping hourly snapshot, last snapshot too recent",
|
||||
"last_snapshot", lastSnapshot,
|
||||
"min_interval_seconds", minIntervalSeconds,
|
||||
)
|
||||
c.FirstHourlySnapshotCheck = false
|
||||
return nil
|
||||
}
|
||||
c.FirstHourlySnapshotCheck = false
|
||||
}
|
||||
|
||||
tableName, err := hourlyInventoryTableName(startTime)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -60,16 +84,10 @@ func (c *CronTask) RunVcenterSnapshotHourly(ctx context.Context, logger *slog.Lo
|
||||
if err := ensureDailyInventoryTable(ctx, dbConn, tableName); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := report.EnsureSnapshotRegistry(ctx, c.Database); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := report.RegisterSnapshot(ctx, c.Database, "hourly", tableName, startTime); err != nil {
|
||||
c.Logger.Warn("failed to register hourly snapshot", "error", err, "table", tableName)
|
||||
}
|
||||
|
||||
// reload settings in case vcenter list has changed
|
||||
c.Settings.ReadYMLSettings()
|
||||
|
||||
var wg sync.WaitGroup
|
||||
var errCount int64
|
||||
concurrencyLimit := c.Settings.Values.Settings.HourlySnapshotConcurrency
|
||||
|
||||
@@ -9,8 +9,9 @@ import (
|
||||
|
||||
// CronTask stores runtime information to be used by tasks
|
||||
type CronTask struct {
|
||||
Logger *slog.Logger
|
||||
Database db.Database
|
||||
Settings *settings.Settings
|
||||
VcCreds *vcenter.VcenterLogin
|
||||
Logger *slog.Logger
|
||||
Database db.Database
|
||||
Settings *settings.Settings
|
||||
VcCreds *vcenter.VcenterLogin
|
||||
FirstHourlySnapshotCheck bool
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user