aboutsummaryrefslogtreecommitdiffstats
path: root/models/actions/run_job.go
diff options
context:
space:
mode:
authorsillyguodong <33891828+sillyguodong@users.noreply.github.com>2023-07-24 14:11:27 +0800
committerGitHub <noreply@github.com>2023-07-24 06:11:27 +0000
commitf5c7d4cfddfe7fc615199a7438749ed79c40361f (patch)
tree10f29b006b8325519fcfc7b31e3d63ed0b1fee7d /models/actions/run_job.go
parent674df05b16f396bf6f2a952923b9c2dfe371415b (diff)
downloadgitea-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_job.go')
-rw-r--r--models/actions/run_job.go7
1 files changed, 7 insertions, 0 deletions
diff --git a/models/actions/run_job.go b/models/actions/run_job.go
index 0002e50770..c7620cd8bc 100644
--- a/models/actions/run_job.go
+++ b/models/actions/run_job.go
@@ -111,6 +111,13 @@ func UpdateRunJob(ctx context.Context, job *ActionRunJob, cond builder.Cond, col
return affected, nil
}
+ if affected != 0 && util.SliceContains(cols, "status") && job.Status.IsWaiting() {
+ // if the status of job changes to waiting again, increase tasks version.
+ if err := IncreaseTaskVersion(ctx, job.OwnerID, job.RepoID); err != nil {
+ return affected, err
+ }
+ }
+
if job.RunID == 0 {
var err error
if job, err = GetRunJobByID(ctx, job.ID); err != nil {