Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into support-ollama-api
Browse files Browse the repository at this point in the history
  • Loading branch information
haraldschilly committed Feb 27, 2024
2 parents ed19f8c + 3029494 commit e06be12
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 60 deletions.
7 changes: 7 additions & 0 deletions src/packages/jupyter/kernel/kernel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,13 @@ export async function initJupyterRedux(syncdb: SyncDB, client: Client) {
);
}

export async function getJupyterRedux(syncdb: SyncDB) {
const project_id = syncdb.project_id;
const path = original_path(syncdb.get_path());
const name = redux_name(project_id, path);
return { actions: redux.getActions(name), store: redux.getStore(name) };
}

// Remove the store/actions for a given Jupyter notebook,
// and also close the kernel if it is running.
export async function removeJupyterRedux(
Expand Down
28 changes: 11 additions & 17 deletions src/packages/next/components/landing/cocalc-com-features.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,8 @@ export function CoCalcComFeatures() {
belowWide={true}
>
<Paragraph>
With {siteName}, you can easily collaborate with colleagues,
students, and friends to edit computational documents. We support
{" "}
With {siteName}, you can easily collaborate with colleagues, students,
and friends to edit computational documents. We support{" "}
<A href={"/features/jupyter-notebook"}>
<strong>Jupyter Notebooks</strong>
</A>
Expand All @@ -72,18 +71,16 @@ export function CoCalcComFeatures() {
</Paragraph>

<Paragraph>
Everyone's code runs in the same per-project environment, which provides
consistent results, synchronized file changes, and automatic revision
history so that you can go back in time when you need to discover what
changed and when. {shareServer && renderShareServer()}
Everyone's code runs in the same per-project environment, which
provides consistent results, synchronized file changes, and automatic
revision history so that you can go back in time when you need to
discover what changed and when. {renderShareServer()}
</Paragraph>

<Paragraph>
Forget the frustration of sending files back and forth between your
collaborators, wasting time reviewing changes, and merging documents. {" "}
<A href={"/auth/sign-up"}>
Get started with {siteName} today.
</A>
collaborators, wasting time reviewing changes, and merging documents.{" "}
<A href={"/auth/sign-up"}>Get started with {siteName} today.</A>
</Paragraph>
</Info>
);
Expand Down Expand Up @@ -162,12 +159,9 @@ export function CoCalcComFeatures() {

return (
<>
{ " " }You can even publish your { siteName } creations to share with
anyone via the built-in { " " }
<A href={ join(basePath, "/share")}>
share server
</A>
.
{" "}
You can even publish your {siteName} creations to share with anyone via
the built-in <A href={"/share/public_paths/page/1"}>share server</A>.
</>
);
}
Expand Down
7 changes: 0 additions & 7 deletions src/packages/project/browser-websocket/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,6 @@ async function handleApiCall(data: Mesg, spark): Promise<any> {
case "prettier_string": // deprecated
case "formatter_string":
return await run_formatter_string(data.path, data.str, data.options, log);
case "jupyter":
// DEPRECATED: The "jupyter" endpoint is only here for browser client
// backward compatibility. Can be safely deleted soon, but not immediately
// to make the release easier
return await jupyter(data.path, data.endpoint, data.query);
case "exec":
if (data.opts?.compute_server_id) {
if (data.opts.filesystem) {
Expand Down Expand Up @@ -222,8 +217,6 @@ async function listing(
}
}

import { handleApiRequest as jupyter } from "@cocalc/jupyter/kernel/websocket-api";

// Execute code
import { executeCode } from "@cocalc/backend/execute-code";

Expand Down
90 changes: 56 additions & 34 deletions src/packages/project/sync/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ silently swallowed in persistent mode...
// and https://github.com/sagemathinc/cocalc/issues/5823
// and https://github.com/sagemathinc/cocalc/issues/5617

// Setting this to 0 to optimize resource usage and because opening files
// is fast, and also on the current tab gets opened on refresh anyways.

const CLOSE_DELAY_MS = 0;

// This is a hard upper bound on the number of browser sessions that could
// have the same file open at once. We put some limit on it, to at least
// limit problems from bugs which crash projects (since each connection uses
Expand Down Expand Up @@ -56,7 +51,7 @@ import {
// @ts-ignore -- typescript nonsense.
const _ = set_debug;

import { init_syncdoc } from "./sync-doc";
import { init_syncdoc, getSyncDocFromSyncTable } from "./sync-doc";
import { key, register_synctable } from "./open-synctables";
import { reuseInFlight } from "@cocalc/util/reuse-in-flight";
import { once } from "@cocalc/util/async-utils";
Expand All @@ -68,6 +63,7 @@ import { register_project_status_table } from "./project-status";
import { register_usage_info_table } from "./usage-info";
import type { MergeType } from "@cocalc/sync/table/synctable";
import Client from "@cocalc/sync-client";
import { getJupyterRedux } from "@cocalc/jupyter/kernel";

type Query = { [key: string]: any };

Expand Down Expand Up @@ -373,7 +369,7 @@ class SyncTableChannel {
}
}

this.check_if_should_close();
this.check_if_should_save_or_close();
}

private send_synctable_to_browser(spark: Spark): void {
Expand All @@ -389,18 +385,20 @@ class SyncTableChannel {
this.channel.write(x);
}

/* Check if we should close, e.g., due to no connected clients. */
private check_if_should_close(): void {
if (this.closed || this.persistent) {
// don't bother if either already closed, or the persistent option is set.
/* This is called when a user disconnects. This always triggers a save to
disk. It may also trigger closing the file in some cases. */
private async check_if_should_save_or_close() {
if (this.closed) {
// don't bother if either already closed
return;
}
const { n } = this.num_connections;
if (n === 0) {
this.log("check_if_should_close -- ", n, " -- do a save and maybe close");
this.save_and_close_if_possible();
} else {
this.log("check_if_should_close -- ", n, " -- do not close");
this.log("check_if_should_save_or_close: save to disk if possible");
await this.save_if_possible();
const { n } = this.num_connections ?? {};
this.log("check_if_should_save_or_close", { n });
if (!this.persistent && n === 0) {
this.log("check_if_should_save_or_close: close if possible");
await this.close_if_possible();
}
}

Expand Down Expand Up @@ -450,33 +448,57 @@ class SyncTableChannel {
this.channel.write(x);
}

private async save_and_close_if_possible(): Promise<void> {
private async save_if_possible(): Promise<void> {
if (this.closed || this.closing) {
return; // closing or already closed
}
this.log("save_and_close_if_possible: no connections, so saving...");
this.log("save_if_possible: saves changes to database");
await this.synctable.save();
if (this.synctable.table === "syncstrings") {
this.log("save_if_possible: also fetch syncdoc");
const syncdoc = getSyncDocFromSyncTable(this.synctable);
if (syncdoc != null) {
const path = syncdoc.get_path();
this.log("save_if_possible: saving syncdoc to disk", { path });
if (path.endsWith(".sage-jupyter2")) {
// treat jupyter notebooks in a special way, since they have
// an aux .ipynb file that the syncdoc doesn't know about. In
// this case we save the ipynb to disk, not just the hidden
// syncdb file.
const { actions } = await getJupyterRedux(syncdoc);
if (actions == null) {
this.log("save_if_possible: jupyter -- actions is null");
} else {
if (!actions.isCellRunner()) {
this.log("save_if_possible: jupyter -- not cell runner");
return;
}
this.log("save_if_possible: jupyter -- saving to ipynb");
await actions.save_ipynb_file();
}
}
await syncdoc.save_to_disk();
} else {
this.log("save_if_possible: no syncdoc");
}
}
}

private async close_if_possible(): Promise<void> {
if (this.closed || this.closing) {
return; // closing or already closed
}
const { n, changed } = this.num_connections;
const delay = Date.now() - changed.valueOf();
this.log(
`save_and_close_if_possible: after save there are ${n} connections and delay=${delay}`,
`close_if_possible: there are ${n} connections and delay=${delay}`,
);
if (n === 0) {
if (delay < CLOSE_DELAY_MS) {
this.log(`save_and_close_if_possible: wait a bit then try again`);
setTimeout(
this.check_if_should_close.bind(this),
1000 + CLOSE_DELAY_MS - delay,
);
} else {
this.log(
`save_and_close_if_possible: close this SyncTableChannel atomically`,
);
// actually close
this.close();
}
this.log(`close_if_possible: close this SyncTableChannel atomically`);
// actually close
this.close();
} else {
this.log(`save_and_close_if_possible: NOT closing this SyncTableChannel`);
this.log(`close_if_possible: NOT closing this SyncTableChannel`);
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/packages/project/sync/sync-doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ export function get_syncdoc(path: string): SyncDoc | undefined {
return syncDocs.get(path);
}

export function getSyncDocFromSyncTable(synctable: SyncTable) {
const { opts } = get_type_and_opts(synctable);
return get_syncdoc(opts.path);
}

async function init_syncdoc_async(
client: Client,
synctable: SyncTable,
Expand Down
2 changes: 1 addition & 1 deletion src/packages/server/salesloft/money.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export async function updateMoney(cutoff: string = "2 days") {
}
const data = await getMoneyData(account_id);
log.debug("updateMoney: ", { salesloft_id: id, account_id, data });
await update(id, data);
await update(id, { custom_fields: data });
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/packages/util/smc-version.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/* autogenerated by the update_version script */
exports.version=1707629396;
exports.version=1709012686;

0 comments on commit e06be12

Please sign in to comment.