@@ -51,6 +51,11 @@ type ActionRunner struct {
51
51
Deleted timeutil.TimeStamp `xorm:"deleted"`
52
52
}
53
53
54
+ const (
55
+ RunnerOfflineTime = time .Minute
56
+ RunnerIdleTime = 10 * time .Second
57
+ )
58
+
54
59
// BelongsToOwnerName before calling, should guarantee that all attributes are loaded
55
60
func (r * ActionRunner ) BelongsToOwnerName () string {
56
61
if r .RepoID != 0 {
@@ -76,11 +81,12 @@ func (r *ActionRunner) BelongsToOwnerType() types.OwnerType {
76
81
return types .OwnerTypeSystemGlobal
77
82
}
78
83
84
+ // if the logic here changed, you should also modify FindRunnerOptions.ToCond
79
85
func (r * ActionRunner ) Status () runnerv1.RunnerStatus {
80
- if time .Since (r .LastOnline .AsTime ()) > time . Minute {
86
+ if time .Since (r .LastOnline .AsTime ()) > RunnerOfflineTime {
81
87
return runnerv1 .RunnerStatus_RUNNER_STATUS_OFFLINE
82
88
}
83
- if time .Since (r .LastActive .AsTime ()) > 10 * time . Second {
89
+ if time .Since (r .LastActive .AsTime ()) > RunnerIdleTime {
84
90
return runnerv1 .RunnerStatus_RUNNER_STATUS_IDLE
85
91
}
86
92
return runnerv1 .RunnerStatus_RUNNER_STATUS_ACTIVE
@@ -153,6 +159,7 @@ type FindRunnerOptions struct {
153
159
OwnerID int64
154
160
Sort string
155
161
Filter string
162
+ IsOnline util.OptionalBool
156
163
WithAvailable bool // not only runners belong to, but also runners can be used
157
164
}
158
165
@@ -178,6 +185,12 @@ func (opts FindRunnerOptions) ToConds() builder.Cond {
178
185
if opts .Filter != "" {
179
186
cond = cond .And (builder.Like {"name" , opts .Filter })
180
187
}
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
+ }
181
194
return cond
182
195
}
183
196
0 commit comments