diff --git a/action-runner/dist/index.js b/action-runner/dist/index.js index ae91d60..661462d 100644 --- a/action-runner/dist/index.js +++ b/action-runner/dist/index.js @@ -30641,7 +30641,7 @@ const exec = __importStar(__nccwpck_require__(5236)); const path = __importStar(__nccwpck_require__(6928)); const fs = __importStar(__nccwpck_require__(1943)); const process_1 = __importDefault(__nccwpck_require__(932)); -const ws_1 = __importDefault(__nccwpck_require__(1354)); +const ws_1 = __importStar(__nccwpck_require__(1354)); let workspace; let currentCommand = null; async function run() { @@ -30716,12 +30716,19 @@ async function setupWs(url, msg) { }); 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()}`); }); return ws; } +function heartbeat(ws) { + if (ws.readyState == ws_1.OPEN) { + ws.ping(); + setTimeout(() => heartbeat(ws), 10 * 1000); + } +} function getRunURL() { return `${process_1.default.env['GITHUB_SERVER_URL']}/${process_1.default.env['GITHUB_REPOSITORY']}/actions/runs/${process_1.default.env['GITHUB_RUN_ID']}`; } diff --git a/action-runner/src/main.ts b/action-runner/src/main.ts index 6ba9098..45ff4cf 100644 --- a/action-runner/src/main.ts +++ b/action-runner/src/main.ts @@ -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 | null = null; @@ -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()}`) @@ -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']}` }