diff options
author | yp05327 <576951401@qq.com> | 2023-12-19 01:06:19 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-18 16:06:19 +0000 |
commit | 4ea522fecfd8f2d6b51466cb9ab6772f4594bf2e (patch) | |
tree | c8e67bf4ea8b1bca4adb409664f054b9113710c8 /models/actions | |
parent | e02095c5b6e04f70ae6562f5aee169f7ee93cf7a (diff) | |
download | gitea-4ea522fecfd8f2d6b51466cb9ab6772f4594bf2e.tar.gz gitea-4ea522fecfd8f2d6b51466cb9ab6772f4594bf2e.zip |
Only check online runner when detecting matching runners in workflows (#28286)
Mentioned:
[#28277](https://github.com/go-gitea/gitea/issues/28277#issuecomment-1831325276)
We should only check online runner when detecting matching runners in
workflows,
as if runner is not online, the workflow will not run.
![image](https://github.com/go-gitea/gitea/assets/18380374/11855e9d-7241-4b7a-b8d7-49dbb94ba1c5)
Diffstat (limited to 'models/actions')
-rw-r--r-- | models/actions/runner.go | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/models/actions/runner.go b/models/actions/runner.go index 717b770800..5630741550 100644 --- a/models/actions/runner.go +++ b/models/actions/runner.go @@ -51,6 +51,11 @@ type ActionRunner struct { Deleted timeutil.TimeStamp `xorm:"deleted"` } +const ( + RunnerOfflineTime = time.Minute + RunnerIdleTime = 10 * time.Second +) + // BelongsToOwnerName before calling, should guarantee that all attributes are loaded func (r *ActionRunner) BelongsToOwnerName() string { if r.RepoID != 0 { @@ -76,11 +81,12 @@ func (r *ActionRunner) BelongsToOwnerType() types.OwnerType { return types.OwnerTypeSystemGlobal } +// if the logic here changed, you should also modify FindRunnerOptions.ToCond func (r *ActionRunner) Status() runnerv1.RunnerStatus { - if time.Since(r.LastOnline.AsTime()) > time.Minute { + if time.Since(r.LastOnline.AsTime()) > RunnerOfflineTime { return runnerv1.RunnerStatus_RUNNER_STATUS_OFFLINE } - if time.Since(r.LastActive.AsTime()) > 10*time.Second { + if time.Since(r.LastActive.AsTime()) > RunnerIdleTime { return runnerv1.RunnerStatus_RUNNER_STATUS_IDLE } return runnerv1.RunnerStatus_RUNNER_STATUS_ACTIVE @@ -153,6 +159,7 @@ type FindRunnerOptions struct { OwnerID int64 Sort string Filter string + IsOnline util.OptionalBool WithAvailable bool // not only runners belong to, but also runners can be used } @@ -178,6 +185,12 @@ func (opts FindRunnerOptions) ToConds() builder.Cond { if opts.Filter != "" { cond = cond.And(builder.Like{"name", opts.Filter}) } + + if opts.IsOnline.IsTrue() { + cond = cond.And(builder.Gt{"last_online": time.Now().Add(-RunnerOfflineTime).Unix()}) + } else if opts.IsOnline.IsFalse() { + cond = cond.And(builder.Lte{"last_online": time.Now().Add(-RunnerOfflineTime).Unix()}) + } return cond } |