diff options
author | sillyguodong <33891828+sillyguodong@users.noreply.github.com> | 2023-07-24 14:11:27 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-24 06:11:27 +0000 |
commit | f5c7d4cfddfe7fc615199a7438749ed79c40361f (patch) | |
tree | 10f29b006b8325519fcfc7b31e3d63ed0b1fee7d /models/actions/run.go | |
parent | 674df05b16f396bf6f2a952923b9c2dfe371415b (diff) | |
download | gitea-f5c7d4cfddfe7fc615199a7438749ed79c40361f.tar.gz gitea-f5c7d4cfddfe7fc615199a7438749ed79c40361f.zip |
Reduce unnecessary DB queries for Actions tasks (#25199)
Close #24544
Changes:
- Create `action_tasks_version` table to store the latest version of
each scope (global, org and repo).
- When a job with the status of `waiting` is created, the tasks version
of the scopes it belongs to will increase.
- When the status of a job already in the database is updated to
`waiting`, the tasks version of the scopes it belongs to will increase.
- On Gitea side, in `FeatchTask()`, will try to query the
`action_tasks_version` record of the scope of the runner that call
`FetchTask()`. If the record does not exist, will insert a row. Then,
Gitea will compare the version passed from runner to Gitea with the
version in database, if inconsistent, try pick task. Gitea always
returns the latest version from database to the runner.
Related:
- Protocol: https://gitea.com/gitea/actions-proto-def/pulls/10
- Runner: https://gitea.com/gitea/act_runner/pulls/219
Diffstat (limited to 'models/actions/run.go')
-rw-r--r-- | models/actions/run.go | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/models/actions/run.go b/models/actions/run.go index 7b62ff884f..5396c612f6 100644 --- a/models/actions/run.go +++ b/models/actions/run.go @@ -195,6 +195,7 @@ func InsertRun(ctx context.Context, run *ActionRun, jobs []*jobparser.SingleWork } runJobs := make([]*ActionRunJob, 0, len(jobs)) + var hasWaiting bool for _, v := range jobs { id, job := v.Job() needs := job.Needs() @@ -205,6 +206,8 @@ func InsertRun(ctx context.Context, run *ActionRun, jobs []*jobparser.SingleWork status := StatusWaiting if len(needs) > 0 || run.NeedApproval { status = StatusBlocked + } else { + hasWaiting = true } job.Name, _ = util.SplitStringAtByteN(job.Name, 255) runJobs = append(runJobs, &ActionRunJob{ @@ -225,6 +228,13 @@ func InsertRun(ctx context.Context, run *ActionRun, jobs []*jobparser.SingleWork return err } + // if there is a job in the waiting status, increase tasks version. + if hasWaiting { + if err := IncreaseTaskVersion(ctx, run.OwnerID, run.RepoID); err != nil { + return err + } + } + return commiter.Commit() } |