From 5c2598a6672d0b08dca2d55c4a848a36ae91062b Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Wed, 29 Nov 2023 07:05:56 +0000 Subject: [PATCH 1/5] improve --- routers/web/repo/actions/actions.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/routers/web/repo/actions/actions.go b/routers/web/repo/actions/actions.go index 3b10f0b9571e..78ca3a093542 100644 --- a/routers/web/repo/actions/actions.go +++ b/routers/web/repo/actions/actions.go @@ -85,7 +85,9 @@ func List(ctx *context.Context) { } allRunnerLabels := make(container.Set[string]) for _, r := range runners { - allRunnerLabels.AddMultiple(r.AgentLabels...) + if r.IsOnline() { + allRunnerLabels.AddMultiple(r.AgentLabels...) + } } workflows = make([]Workflow, 0, len(entries)) From 5aab4db8fea8e2d2d570a50031299aa0b6f91f1d Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Fri, 1 Dec 2023 02:39:37 +0000 Subject: [PATCH 2/5] improve --- models/actions/runner.go | 15 +++++++++++++-- options/locale/locale_en-US.ini | 2 +- routers/web/repo/actions/actions.go | 7 +++---- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/models/actions/runner.go b/models/actions/runner.go index 717b770800dc..c9a02e97d053 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 bool WithAvailable bool // not only runners belong to, but also runners can be used } @@ -178,6 +185,10 @@ func (opts FindRunnerOptions) ToConds() builder.Cond { if opts.Filter != "" { cond = cond.And(builder.Like{"name", opts.Filter}) } + + if opts.IsOnline { + cond = cond.And(builder.Gt{"last_online": time.Now().Add(-RunnerOfflineTime).Unix()}) + } return cond } diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index fa7eee9bc558..56ab16462365 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -3523,7 +3523,7 @@ runs.commit = Commit runs.scheduled = Scheduled runs.pushed_by = pushed by runs.invalid_workflow_helper = Workflow config file is invalid. Please check your config file: %s -runs.no_matching_runner_helper = No matching runner: %s +runs.no_matching_online_runner_helper = No matching online runner: %s runs.actor = Actor runs.status = Status runs.actors_no_select = All actors diff --git a/routers/web/repo/actions/actions.go b/routers/web/repo/actions/actions.go index 78ca3a093542..66c41148ac18 100644 --- a/routers/web/repo/actions/actions.go +++ b/routers/web/repo/actions/actions.go @@ -77,6 +77,7 @@ func List(ctx *context.Context) { // Get all runner labels runners, err := db.Find[actions_model.ActionRunner](ctx, actions_model.FindRunnerOptions{ RepoID: ctx.Repo.Repository.ID, + IsOnline: true, WithAvailable: true, }) if err != nil { @@ -85,9 +86,7 @@ func List(ctx *context.Context) { } allRunnerLabels := make(container.Set[string]) for _, r := range runners { - if r.IsOnline() { - allRunnerLabels.AddMultiple(r.AgentLabels...) - } + allRunnerLabels.AddMultiple(r.AgentLabels...) } workflows = make([]Workflow, 0, len(entries)) @@ -115,7 +114,7 @@ func List(ctx *context.Context) { continue } if !allRunnerLabels.Contains(ro) { - workflow.ErrMsg = ctx.Locale.Tr("actions.runs.no_matching_runner_helper", ro) + workflow.ErrMsg = ctx.Locale.Tr("actions.runs.no_matching_online_runner_helper", ro) break } } From c35ccfa2e60163b227735c546bbe4a638090988a Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Fri, 1 Dec 2023 02:43:10 +0000 Subject: [PATCH 3/5] improve --- options/locale/locale_en-US.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 56ab16462365..0e19f0f5696d 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -3523,7 +3523,7 @@ runs.commit = Commit runs.scheduled = Scheduled runs.pushed_by = pushed by runs.invalid_workflow_helper = Workflow config file is invalid. Please check your config file: %s -runs.no_matching_online_runner_helper = No matching online runner: %s +runs.no_matching_online_runner_helper = No matching online runner with label: %s runs.actor = Actor runs.status = Status runs.actors_no_select = All actors From 7bf0ec6a04f0af2906dfc7bf408b34d37cd2a4b5 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Mon, 4 Dec 2023 00:26:08 +0000 Subject: [PATCH 4/5] improve --- models/actions/runner.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/models/actions/runner.go b/models/actions/runner.go index c9a02e97d053..5630741550d5 100644 --- a/models/actions/runner.go +++ b/models/actions/runner.go @@ -159,7 +159,7 @@ type FindRunnerOptions struct { OwnerID int64 Sort string Filter string - IsOnline bool + IsOnline util.OptionalBool WithAvailable bool // not only runners belong to, but also runners can be used } @@ -186,8 +186,10 @@ func (opts FindRunnerOptions) ToConds() builder.Cond { cond = cond.And(builder.Like{"name", opts.Filter}) } - if opts.IsOnline { + 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 } From ba8ef8b8e71b0caab0afdad45c63d2bb633079c0 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Mon, 4 Dec 2023 06:50:50 +0000 Subject: [PATCH 5/5] fix --- routers/web/repo/actions/actions.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/routers/web/repo/actions/actions.go b/routers/web/repo/actions/actions.go index 66c41148ac18..6dc4b2d111db 100644 --- a/routers/web/repo/actions/actions.go +++ b/routers/web/repo/actions/actions.go @@ -18,6 +18,7 @@ import ( "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/setting" + "code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/routers/web/repo" "code.gitea.io/gitea/services/convert" @@ -77,7 +78,7 @@ func List(ctx *context.Context) { // Get all runner labels runners, err := db.Find[actions_model.ActionRunner](ctx, actions_model.FindRunnerOptions{ RepoID: ctx.Repo.Repository.ID, - IsOnline: true, + IsOnline: util.OptionalBoolTrue, WithAvailable: true, }) if err != nil {