Skip to content

Commit ee542dc

Browse files
committed
limit reaps to 20 at a time
1 parent 0d3c677 commit ee542dc

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

server/internal/background/activities/reap_functions.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@ func (r *ReapFlyApps) Do(ctx context.Context, req ReapFlyAppsRequest) (*ReapFlyA
7070
repo := funcrepo.New(r.db)
7171

7272
// Get all apps that should be reaped (keeping only the most recent N per project)
73-
appsToReap, err := repo.GetFlyAppsToReap(ctx, pgtype.Int8{Int64: r.keepCount, Valid: true})
73+
appsToReap, err := repo.GetFlyAppsToReap(ctx, funcrepo.GetFlyAppsToReapParams{
74+
KeepCount: pgtype.Int8{Int64: r.keepCount, Valid: true},
75+
BatchSize: pgtype.Int8{Int64: 20, Valid: true},
76+
})
7477
if err != nil {
7578
return nil, oops.E(oops.CodeUnexpected, err, "failed to query apps to reap").Log(ctx, logger)
7679
}

server/internal/functions/queries.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ WHERE
135135
rd.deployment_rank > @keep_count
136136
AND fa.status = 'ready'
137137
AND fa.reaped_at IS NULL
138-
ORDER BY fa.created_at ASC;
138+
ORDER BY fa.created_at ASC
139+
LIMIT @batch_size;
139140

140141
-- name: MarkFlyAppReaped :exec
141142
UPDATE fly_apps SET

server/internal/functions/repo/queries.sql.go

Lines changed: 8 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)