@@ -69,16 +69,7 @@ async function getGitHubSelfHostedRunnerState(
69
69
} ) ;
70
70
metricGitHubAppRateLimit ( state . headers ) ;
71
71
72
- return {
73
- id : state . data . id ,
74
- name : state . data . name ,
75
- busy : state . data . busy ,
76
- status : state . data . status ,
77
- os : state . data . os ,
78
- labels : state . data . labels ,
79
- runner_group_id : state . data . runner_group_id ,
80
- ephemeral : state . data . ephemeral ,
81
- } ;
72
+ return state . data ;
82
73
}
83
74
84
75
async function getGitHubRunnerBusyState ( client : Octokit , ec2runner : RunnerInfo , runnerId : number ) : Promise < boolean > {
@@ -221,33 +212,35 @@ async function markOrphan(instanceId: string): Promise<void> {
221
212
}
222
213
}
223
214
224
- async function lastChanceCheckOrphanRunner ( runner : RunnerList ) : Promise < void > {
215
+ async function unmarkOrphan ( instanceId : string ) : Promise < void > {
216
+ try {
217
+ await untag ( instanceId , [ { Key : 'ghr:orphan' , Value : 'true' } ] ) ;
218
+ logger . info ( `Runner '${ instanceId } ' unmarked as orphan.` ) ;
219
+ } catch ( e ) {
220
+ logger . error ( `Failed to unmark runner '${ instanceId } ' as orphan.` , { error : e } ) ;
221
+ }
222
+ }
223
+
224
+ async function lastChanceCheckOrphanRunner ( runner : RunnerList ) : Promise < boolean > {
225
225
const client = await getOrCreateOctokit ( runner as RunnerInfo ) ;
226
226
const runnerId = parseInt ( runner . runnerId || '0' ) ;
227
227
const ec2Instance = runner as RunnerInfo ;
228
228
const state = await getGitHubSelfHostedRunnerState ( client , ec2Instance , runnerId ) ;
229
+ var isOrphan = false ;
229
230
logger . debug ( `Runner is currently '${ runner . instanceId } ' state: ${ JSON . stringify ( state ) } ` ) ;
230
- if ( state . status === 'online' && state . busy ) {
231
- logger . info ( `Runner '${ runner . instanceId } ' is orphan, but is online and busy.` ) ;
232
- await untag ( runner . instanceId , [ { Key : 'ghr:orphan' , Value : 'true' } ] ) ;
233
- } else if ( state . status === 'offline' ) {
234
- logger . warn ( `Runner '${ runner . instanceId } ' is orphan.` ) ;
235
- logger . info ( `Terminating orphan runner '${ runner . instanceId } '` ) ;
236
- await terminateRunner ( runner . instanceId ) . catch ( ( e ) => {
237
- logger . error ( `Failed to terminate orphan runner '${ runner . instanceId } '` , { error : e } ) ;
238
- } ) ;
231
+ if ( state . status === 'offline' ) {
232
+ isOrphan = true ;
239
233
}
234
+ return isOrphan
240
235
}
241
236
242
237
async function terminateOrphan ( environment : string ) : Promise < void > {
243
238
try {
244
239
const orphanRunners = await listEC2Runners ( { environment, orphan : true } ) ;
245
240
246
241
for ( const runner of orphanRunners ) {
247
- // do we have a valid runnerId? then we are in a Jit Runner scenario else, use old method
248
242
if ( runner . runnerId ) {
249
- logger . debug ( `Runner '${ runner . instanceId } ' is orphan, but has a runnerId.` ) ;
250
- await lastChanceCheckOrphanRunner ( runner ) ;
243
+ await lastChanceCheckOrphanRunner ( runner ) ? terminateRunner ( runner . instanceId ) : unmarkOrphan ( runner . instanceId ) ;
251
244
} else {
252
245
logger . info ( `Terminating orphan runner '${ runner . instanceId } '` ) ;
253
246
await terminateRunner ( runner . instanceId ) . catch ( ( e ) => {
0 commit comments