Skip to content

Commit 4ea522f

Browse files
authored
Only check online runner when detecting matching runners in workflows (#28286)
Mentioned: [#28277](#28277 (comment)) 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)
1 parent e02095c commit 4ea522f

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

models/actions/runner.go

+15-2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ type ActionRunner struct {
5151
Deleted timeutil.TimeStamp `xorm:"deleted"`
5252
}
5353

54+
const (
55+
RunnerOfflineTime = time.Minute
56+
RunnerIdleTime = 10 * time.Second
57+
)
58+
5459
// BelongsToOwnerName before calling, should guarantee that all attributes are loaded
5560
func (r *ActionRunner) BelongsToOwnerName() string {
5661
if r.RepoID != 0 {
@@ -76,11 +81,12 @@ func (r *ActionRunner) BelongsToOwnerType() types.OwnerType {
7681
return types.OwnerTypeSystemGlobal
7782
}
7883

84+
// if the logic here changed, you should also modify FindRunnerOptions.ToCond
7985
func (r *ActionRunner) Status() runnerv1.RunnerStatus {
80-
if time.Since(r.LastOnline.AsTime()) > time.Minute {
86+
if time.Since(r.LastOnline.AsTime()) > RunnerOfflineTime {
8187
return runnerv1.RunnerStatus_RUNNER_STATUS_OFFLINE
8288
}
83-
if time.Since(r.LastActive.AsTime()) > 10*time.Second {
89+
if time.Since(r.LastActive.AsTime()) > RunnerIdleTime {
8490
return runnerv1.RunnerStatus_RUNNER_STATUS_IDLE
8591
}
8692
return runnerv1.RunnerStatus_RUNNER_STATUS_ACTIVE
@@ -153,6 +159,7 @@ type FindRunnerOptions struct {
153159
OwnerID int64
154160
Sort string
155161
Filter string
162+
IsOnline util.OptionalBool
156163
WithAvailable bool // not only runners belong to, but also runners can be used
157164
}
158165

@@ -178,6 +185,12 @@ func (opts FindRunnerOptions) ToConds() builder.Cond {
178185
if opts.Filter != "" {
179186
cond = cond.And(builder.Like{"name", opts.Filter})
180187
}
188+
189+
if opts.IsOnline.IsTrue() {
190+
cond = cond.And(builder.Gt{"last_online": time.Now().Add(-RunnerOfflineTime).Unix()})
191+
} else if opts.IsOnline.IsFalse() {
192+
cond = cond.And(builder.Lte{"last_online": time.Now().Add(-RunnerOfflineTime).Unix()})
193+
}
181194
return cond
182195
}
183196

options/locale/locale_en-US.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -3525,7 +3525,7 @@ runs.commit = Commit
35253525
runs.scheduled = Scheduled
35263526
runs.pushed_by = pushed by
35273527
runs.invalid_workflow_helper = Workflow config file is invalid. Please check your config file: %s
3528-
runs.no_matching_runner_helper = No matching runner: %s
3528+
runs.no_matching_online_runner_helper = No matching online runner with label: %s
35293529
runs.actor = Actor
35303530
runs.status = Status
35313531
runs.actors_no_select = All actors

routers/web/repo/actions/actions.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"code.gitea.io/gitea/modules/context"
1919
"code.gitea.io/gitea/modules/git"
2020
"code.gitea.io/gitea/modules/setting"
21+
"code.gitea.io/gitea/modules/util"
2122
"code.gitea.io/gitea/routers/web/repo"
2223
"code.gitea.io/gitea/services/convert"
2324

@@ -77,6 +78,7 @@ func List(ctx *context.Context) {
7778
// Get all runner labels
7879
runners, err := db.Find[actions_model.ActionRunner](ctx, actions_model.FindRunnerOptions{
7980
RepoID: ctx.Repo.Repository.ID,
81+
IsOnline: util.OptionalBoolTrue,
8082
WithAvailable: true,
8183
})
8284
if err != nil {
@@ -113,7 +115,7 @@ func List(ctx *context.Context) {
113115
continue
114116
}
115117
if !allRunnerLabels.Contains(ro) {
116-
workflow.ErrMsg = ctx.Locale.Tr("actions.runs.no_matching_runner_helper", ro)
118+
workflow.ErrMsg = ctx.Locale.Tr("actions.runs.no_matching_online_runner_helper", ro)
117119
break
118120
}
119121
}

0 commit comments

Comments
 (0)