Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/util/compute/manager.ts
Views: 687
export const COMPUTER_SERVER_DB_NAME = ".compute-server.syncdb";12export const SYNCDB_PARAMS = {3path: COMPUTER_SERVER_DB_NAME,4primary_keys: ["path"],5ephemeral: false,6cursors: true,7};89export const COMPUTER_SERVER_CURSOR_TYPE = "compute-server";1011// This is relevant for compute servers. It's how long until we give up12// on the compute server if it doesn't actively update its cursor state.13// Note that in most cases the compute server will explicitly delete its14// cursor on termination so switching is instant. This is a "just in case",15// so things aren't broken forever, e.g., in case of a crash.16export const COMPUTE_THRESH_MS = 15 * 1000;1718/*19For sync, we make the id of each compute server a uuid that is a simple20function of the id, so the client_id is stable and easy to identify.21*/2223const COMPUTER_SERVER_UUID_END = "0000-4000-8000-000000000000";24export function isEncodedNumUUID(uuid: string | undefined): boolean {25return !!uuid?.endsWith(COMPUTER_SERVER_UUID_END);26}2728export function encodeIntToUUID(num: number | string): string {29if (typeof num == "string") {30num = parseInt(num);31}32// Convert to hexadecimal33let hex = num.toString(16);34while (hex.length < 8) {35hex = "0" + hex;36}37return `${hex}-${COMPUTER_SERVER_UUID_END}`;38}3940export function decodeUUIDtoNum(uuid: string): number {41if (!isEncodedNumUUID(uuid)) {42throw Error(`uuid is not an encoded number -- ${uuid}`);43}44return parseInt(uuid.slice(0, 8), 16);45}464748