Skip to content

Commit

Permalink
Heartbeat every 10 seconds
Browse files Browse the repository at this point in the history
  • Loading branch information
Matyrobbrt committed Jan 22, 2025
1 parent e7da6ee commit 933fb0a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
9 changes: 8 additions & 1 deletion action-runner/dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion action-runner/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as fs from 'fs/promises'

import process from 'process'

import WebSocket from 'ws'
import WebSocket, {OPEN} from 'ws'

let workspace: string;
let currentCommand: Promise<ExecOutput> | null = null;
Expand Down Expand Up @@ -90,6 +90,7 @@ export async function setupWs(url: string, msg: (ws: WebSocket, message: any) =>

ws.on('open', () => {
console.error(`Connection opened... awaiting command`)
heartbeat(ws)
})
ws.on('close', (code, reason) => {
console.error(`Connection closed with code ${code}: ${reason.toString()}`)
Expand All @@ -98,6 +99,13 @@ export async function setupWs(url: string, msg: (ws: WebSocket, message: any) =>
return ws
}

function heartbeat(ws: WebSocket) {
if (ws.readyState == OPEN) {
ws.ping()
setTimeout(() => heartbeat(ws), 10 * 1000)
}
}

export function getRunURL(): string {
return `${process.env['GITHUB_SERVER_URL']}/${process.env['GITHUB_REPOSITORY']}/actions/runs/${process.env['GITHUB_RUN_ID']}`
}

0 comments on commit 933fb0a

Please # to comment.