Skip to content

Commit

Permalink
HMS-5202: don't always rerun failed snaps
Browse files Browse the repository at this point in the history
  • Loading branch information
jlsherrill committed Dec 20, 2024
1 parent 57399dc commit 5a9c8fc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
7 changes: 4 additions & 3 deletions pkg/dao/repository_configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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")
Expand Down
6 changes: 3 additions & 3 deletions pkg/dao/repository_configs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}},
},
Expand Down

0 comments on commit 5a9c8fc

Please sign in to comment.