Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HMS-5202: don't always rerun failed snaps #928

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/external-repos/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,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 @@ -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
Loading