Skip to content

Commit de5a83a

Browse files
committed
feat: Query the old action runs in DB (#26219)
As the Issue (#26219) mentioned, this is a database-level support to query the obsolete actions runs. I'll temporarily add a draft for further work.
1 parent 581e52b commit de5a83a

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

models/actions/run.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,23 @@ func GetLatestRun(ctx context.Context, repoID int64) (*ActionRun, error) {
377377
return run, nil
378378
}
379379

380+
func GetRunsBeforeDate(ctx context.Context, repoID int64, beforeDate time.Time) ([]*ActionRun, error) {
381+
var runs []*ActionRun
382+
err := db.GetEngine(ctx).
383+
Where("repo_id = ?", repoID).
384+
And("created < ?", beforeDate).
385+
Find(&runs)
386+
if err != nil {
387+
return nil, err
388+
}
389+
return runs, nil
390+
}
391+
392+
func GetObsoleteRuns(ctx context.Context, repoID int64, days int) ([]*ActionRun, error) {
393+
thresholdDate := time.Now().AddDate(0, 0, -days)
394+
return GetRunsBeforeDate(ctx, repoID, thresholdDate)
395+
}
396+
380397
func GetWorkflowLatestRun(ctx context.Context, repoID int64, workflowFile, branch, event string) (*ActionRun, error) {
381398
var run ActionRun
382399
q := db.GetEngine(ctx).Where("repo_id=?", repoID).

0 commit comments

Comments
 (0)