@@ -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
5560func (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
7985func (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) toCond() 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
0 commit comments