From 5a9c8fc783382160cf8ddee59f60e4a058f46709 Mon Sep 17 00:00:00 2001 From: Justin Sherrill Date: Fri, 20 Dec 2024 09:11:34 -0500 Subject: [PATCH] HMS-5202: don't always rerun failed snaps --- pkg/dao/repository_configs.go | 7 ++++--- pkg/dao/repository_configs_test.go | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/pkg/dao/repository_configs.go b/pkg/dao/repository_configs.go index 2a102bcb2..c39415643 100644 --- a/pkg/dao/repository_configs.go +++ b/pkg/dao/repository_configs.go @@ -274,7 +274,7 @@ func (r repositoryConfigDaoImpl) extraReposToSnapshot(pdb *gorm.DB, notIn *gorm. Joins("LEFT JOIN tasks on last_snapshot_task_uuid = tasks.id"). Where("repository_configurations.uuid not in (?)", notIn.Select("repository_configurations.uuid")). Where(pdb.Or("tasks.status NOT IN ?", []string{config.TaskStatusPending, config.TaskStatusRunning})). - Order("tasks.finished_at ASC NULLS FIRST").Limit(count).Find(&extra) + Order("tasks.queued_at ASC NULLS FIRST").Limit(count).Find(&extra) return extra, query.Error } @@ -287,13 +287,14 @@ func (r repositoryConfigDaoImpl) InternalOnly_ListReposToSnapshot(ctx context.Co var query *gorm.DB pdb := r.db.WithContext(ctx) - interval := fmt.Sprintf("%v hours", config.SnapshotForceInterval) + // subtract 1, as the next run will be more than 24 hours + interval := fmt.Sprintf("%v hours", config.SnapshotForceInterval-1) if config.Get().Options.AlwaysRunCronTasks { query = pdb.Where("snapshot IS TRUE") } else { query = pdb.Where("snapshot IS TRUE").Joins("LEFT JOIN tasks on last_snapshot_task_uuid = tasks.id"). Where(pdb.Where("tasks.queued_at <= (now() - cast(? as interval))", interval). - Or("tasks.status NOT IN ?", []string{config.TaskStatusCompleted, config.TaskStatusPending, config.TaskStatusRunning}). + Where("tasks.status NOT IN ?", []string{config.TaskStatusPending, config.TaskStatusRunning}). Or("last_snapshot_task_uuid is NULL")) } query = query.Joins("INNER JOIN repositories r on r.uuid = repository_configurations.repository_uuid") diff --git a/pkg/dao/repository_configs_test.go b/pkg/dao/repository_configs_test.go index 62ae85fdb..4e91ef5d3 100644 --- a/pkg/dao/repository_configs_test.go +++ b/pkg/dao/repository_configs_test.go @@ -2456,11 +2456,11 @@ func (suite *RepositoryConfigSuite) TestListReposToSnapshot() { { Name: "Previous Snapshot Failed", Opts: &seeds.TaskSeedOptions{RepoConfigUUID: repo.UUID, OrgID: repo.OrgID, Status: config.TaskStatusFailed}, - Included: true, + Included: false, }, { - Name: "Previous Snapshot Failed, and url specified", - Opts: &seeds.TaskSeedOptions{RepoConfigUUID: repo.UUID, OrgID: repo.OrgID, Status: config.TaskStatusFailed}, + Name: "Previous Snapshot Failed, yesterday", + Opts: &seeds.TaskSeedOptions{RepoConfigUUID: repo.UUID, OrgID: repo.OrgID, Status: config.TaskStatusFailed, QueuedAt: &yesterday}, Included: true, Filter: &ListRepoFilter{URLs: &[]string{repo.URL}}, },