Skip to content

Commit

Permalink
HMS-5202: don't always rerun failed snaps (#928)
Browse files Browse the repository at this point in the history
  • Loading branch information
jlsherrill authored Dec 20, 2024
1 parent 5d14ee7 commit c3e479f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions cmd/external-repos/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ func enqueueSnapshotRepos(ctx context.Context, urls *[]string, interval *int) er
}
taskUuid, err := c.Enqueue(t)
if err == nil {
log.Info().Msgf("enqueued snapshot for repository config %v", repo.UUID)
if err := repoConfigDao.UpdateLastSnapshotTask(ctx, taskUuid.String(), repo.OrgID, repo.RepositoryUUID); err != nil {
log.Error().Err(err).Msgf("error UpdatingLastSnapshotTask task during nightly job")
}
Expand Down
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 @@ -2491,11 +2491,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 c3e479f

Please sign in to comment.