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.
This commit is contained in:
cclvi256 2024-12-19 22:37:43 +08:00
parent 581e52b3e7
commit de5a83a685
No known key found for this signature in database

View File

@ -377,6 +377,23 @@ func GetLatestRun(ctx context.Context, repoID int64) (*ActionRun, error) {
return run, nil
}
func GetRunsBeforeDate(ctx context.Context, repoID int64, beforeDate time.Time) ([]*ActionRun, error) {
var runs []*ActionRun
err := db.GetEngine(ctx).
Where("repo_id = ?", repoID).
And("created < ?", beforeDate).
Find(&runs)
if err != nil {
return nil, err
}
return runs, nil
}
func GetObsoleteRuns(ctx context.Context, repoID int64, days int) ([]*ActionRun, error) {
thresholdDate := time.Now().AddDate(0, 0, -days)
return GetRunsBeforeDate(ctx, repoID, thresholdDate)
}
func GetWorkflowLatestRun(ctx context.Context, repoID int64, workflowFile, branch, event string) (*ActionRun, error) {
var run ActionRun
q := db.GetEngine(ctx).Where("repo_id=?", repoID).