1
+ import logging
1
2
from datetime import datetime , timedelta
2
3
from enum import Enum
3
4
from typing import List , Literal , Optional
10
11
from redis_om import Field , NotFoundError
11
12
12
13
from runner_manager .clients .github import GitHub
13
- from runner_manager .logging import log
14
14
from runner_manager .models .base import BaseModel
15
15
16
+ log = logging .getLogger (__name__ )
16
17
# Ideally the runner model would have been inherited
17
18
# from githubkit.rest.models.Runner, like the following:
18
19
# class Runner(BaseModel, githubkit.rest.models.Runner):
25
26
26
27
class RunnerStatus (str , Enum ):
27
28
online = "online"
28
- idle = "idle"
29
29
offline = "offline"
30
30
31
31
@@ -89,17 +89,19 @@ def find_from_webhook(cls, webhook: WorkflowJobEvent) -> "Runner":
89
89
return runner
90
90
91
91
@property
92
- def is_online (self ) -> bool :
93
- """Check if the runner is online
92
+ def is_active (self ) -> bool :
93
+ """Check if the runner is active.
94
+
95
+ An active runner is a runner that is running a job.
94
96
95
97
Returns:
96
- bool: True if the runner is online , False otherwise.
98
+ bool: True if the runner is active , False otherwise.
97
99
"""
98
- return self .status == RunnerStatus .online
100
+ return self .status == RunnerStatus .online and self . busy is True
99
101
100
102
@property
101
103
def is_offline (self ) -> bool :
102
- """Check if the runner is offline
104
+ """Check if the runner is offline.
103
105
104
106
Returns:
105
107
bool: True if the runner is offline, False otherwise.
@@ -108,12 +110,15 @@ def is_offline(self) -> bool:
108
110
109
111
@property
110
112
def is_idle (self ) -> bool :
111
- """Check if the runner is idle
113
+ """Check if the runner is idle.
114
+
115
+ An idle runner is a runner that is online and
116
+ properly attached to GitHub but is not running a job.
112
117
113
118
Returns:
114
119
bool: True if the runner is idle, False otherwise.
115
120
"""
116
- return self .status == RunnerStatus .idle
121
+ return self .status == RunnerStatus .online and self . busy is False
117
122
118
123
@property
119
124
def time_since_created (self ) -> timedelta :
@@ -144,7 +149,7 @@ def time_to_start_expired(self, timeout: timedelta) -> bool:
144
149
return self .is_offline and self .time_since_created > timeout
145
150
146
151
def time_to_live_expired (self , time_to_live : timedelta ) -> bool :
147
- return self .is_online and self .time_since_started > time_to_live
152
+ return self .is_active and self .time_since_started > time_to_live
148
153
149
154
def update_from_github (self , github : GitHub ) -> "Runner" :
150
155
if self .id is not None :
@@ -153,9 +158,9 @@ def update_from_github(self, github: GitHub) -> "Runner":
153
158
org = self .organization , runner_id = self .id
154
159
).parsed_data
155
160
)
156
- self .status = RunnerStatus (self .status )
161
+ self .status = RunnerStatus (github_runner .status )
157
162
self .busy = github_runner .busy
158
- log .info (f"Runner { self .name } status updated to { self .status } " )
163
+ log .info (f"Runner { self .name } status updated to { self .status } " )
159
164
return self .save ()
160
165
161
166
def generate_jit_config (self , github : GitHub ) -> "Runner" :
0 commit comments