diff --git a/deno-runtime/main.ts b/deno-runtime/main.ts index 9bc05e886..f65ecca62 100644 --- a/deno-runtime/main.ts +++ b/deno-runtime/main.ts @@ -28,6 +28,7 @@ type Handlers = { slashcommand: typeof slashcommandHandler; videoconference: typeof videoConferenceHandler; scheduler: typeof handleScheduler; + ping: (method: string, params: unknown) => 'pong'; }; async function requestRouter({ type, payload }: Messenger.JsonRpcRequest): Promise { @@ -37,6 +38,7 @@ async function requestRouter({ type, payload }: Messenger.JsonRpcRequest): Promi slashcommand: slashcommandHandler, videoconference: videoConferenceHandler, scheduler: handleScheduler, + ping: (_method, _params) => 'pong', }; // We're not handling notifications at the moment diff --git a/src/server/runtime/deno/AppsEngineDenoRuntime.ts b/src/server/runtime/deno/AppsEngineDenoRuntime.ts index 02a265409..4191f91e2 100644 --- a/src/server/runtime/deno/AppsEngineDenoRuntime.ts +++ b/src/server/runtime/deno/AppsEngineDenoRuntime.ts @@ -125,6 +125,14 @@ export class DenoRuntimeSubprocessController extends EventEmitter { this.deno = child_process.spawn(denoExePath, options); this.setupListeners(); + this.startPing(); + + queueMicrotask(() => { + if (this.deno.exitCode !== null) { + this.state = 'invalid'; + this.debug('Deno subprocess exited with code %d, signal %s', this.deno.exitCode, this.deno.signalCode); + } + }); } catch (e) { this.state = 'invalid'; console.error('Failed to start Deno subprocess', e); @@ -137,6 +145,24 @@ export class DenoRuntimeSubprocessController extends EventEmitter { this.runtimeManager = manager.getRuntime(); } + private startPing() { + const ping = () => { + const start = Date.now(); + this.sendRequest({ method: 'ping', params: [] }) + .then((result) => { + if (result !== 'pong') { + this.debug(`Expected 'pong', got %s (%d ms)`, result, Date.now() - start); + } + }) + .catch((reason: unknown) => { + this.debug('Ping failed: %s (%d ms)', reason, Date.now() - start); + }); + }; + + ping(); + setInterval(ping, 5000); + } + // Debug purposes, could be deleted later emit(eventName: string | symbol, ...args: any[]): boolean { const hadListeners = super.emit(eventName, ...args);