Skip to content
Open
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
8 changes: 1 addition & 7 deletions engine/sdks/typescript/runner-protocol/src/index.ts

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

34 changes: 25 additions & 9 deletions engine/sdks/typescript/runner/src/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
unreachable,
} from "./utils";
import { importWebSocket } from "./websocket.js";
import type { WebSocketTunnelAdapter } from "./websocket-tunnel-adapter";

Check warning on line 13 in engine/sdks/typescript/runner/src/mod.ts

View workflow job for this annotation

GitHub Actions / quality

lint/correctness/noUnusedImports

This import is unused.

Check warning on line 13 in engine/sdks/typescript/runner/src/mod.ts

View workflow job for this annotation

GitHub Actions / quality

lint/correctness/noUnusedImports

This import is unused.

const KV_EXPIRE: number = 30_000;
const PROTOCOL_VERSION: number = 3;
Expand Down Expand Up @@ -57,30 +57,40 @@
requestId: protocol.RequestId,
request: Request,
) => Promise<Response>;
websocket?: (
websocket: (
runner: Runner,
actorId: string,
ws: any,
requestId: protocol.RequestId,
request: Request,
) => Promise<void>;
) => void;
onActorStart: (
actorId: string,
generation: number,
config: ActorConfig,
) => Promise<void>;
/**
* Called on actor start.
*
* Returns the message indices for hibernating request IDs.
*
* Disconnect any connections that are not in the request ID list.
*/
restoreHibernativeRequests(
actorId: string,
requestId: protocol.RequestId[],
): number[];
onActorStop: (actorId: string, generation: number) => Promise<void>;
getActorHibernationConfig: (
canWebSocketHibernate: (
actorId: string,
requestId: ArrayBuffer,
request: Request,
) => HibernationConfig;
) => boolean;
noAutoShutdown?: boolean;
}

export interface HibernationConfig {
enabled: boolean;
lastMsgIndex: number | undefined;
lastMsgIndex: number;
}

export interface KvListOptions {
Expand All @@ -105,7 +115,6 @@
}

#actors: Map<string, ActorInstance> = new Map();
#actorWebSockets: Map<string, Set<WebSocketTunnelAdapter>> = new Map();

// WebSocket
#pegboardWebSocket?: WebSocket;
Expand Down Expand Up @@ -831,6 +840,11 @@
webSockets: new Set(),
};

this.#tunnel.restoreHibernatingRequests(
actorId,
startCommand.hibernatingRequestIds,
);

this.#actors.set(actorId, instance);

this.#sendActorStateUpdate(actorId, generation, "running");
Expand Down Expand Up @@ -1427,8 +1441,10 @@
}
}

sendWebsocketMessageAck(requestId: ArrayBuffer, index: number) {
this.#tunnel?.__ackWebsocketMessage(requestId, index);
sendHibernatableWebSocketMessageAck(requestId: ArrayBuffer, index: number) {
if (!this.#tunnel)
throw new Error("missing tunnel to send message ack");
this.#tunnel.sendHibernatableWebSocketMessageAck(requestId, index);
}

getServerlessInitPacket(): string | undefined {
Expand Down
Loading
Loading