Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"packageManager": "pnpm@10.13.1",
"scripts": {
"start": "npx turbo watch build",
"build": "npx turbo build",
"test": "npx turbo test",
"test:watch": "npx turbo watch test",
"check-types": "npx turbo check-types",
Expand Down
13 changes: 6 additions & 7 deletions sdks/typescript/runner/src/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import { unreachable, calculateBackoff } from "./utils.js";
import { Tunnel } from "./tunnel.js";
import { WebSocketTunnelAdapter } from "./websocket-tunnel-adapter.js";

const WS = await importWebSocket();

const KV_EXPIRE: number = 30_000;

interface ActorInstance {
Expand Down Expand Up @@ -215,12 +213,12 @@ export class Runner {
}

// MARK: Start
start() {
async start() {
if (this.#started) throw new Error("Cannot call runner.start twice");
this.#started = true;

console.log("[RUNNER] Starting runner");
this.#openPegboardWebSocket();
await this.#openPegboardWebSocket();
this.#openTunnel();

process.on("SIGTERM", this.shutdown.bind(this, false, true));
Expand Down Expand Up @@ -378,7 +376,8 @@ export class Runner {
}

// MARK: Runner protocol
#openPegboardWebSocket() {
async #openPegboardWebSocket() {
const WS = await importWebSocket();
const ws = new WS(this.pegboardUrl, {
headers: {
"x-rivet-target": "runner-ws",
Expand Down Expand Up @@ -1177,13 +1176,13 @@ export class Runner {
`Scheduling reconnect attempt ${this.#reconnectAttempt + 1} in ${delay}ms`,
);

this.#reconnectTimeout = setTimeout(() => {
this.#reconnectTimeout = setTimeout(async () => {
if (!this.#shutdown) {
this.#reconnectAttempt++;
console.log(
`Attempting to reconnect (attempt ${this.#reconnectAttempt})...`,
);
this.#openPegboardWebSocket();
await this.#openPegboardWebSocket();
}
}, delay);
}
Expand Down
Loading