Skip to content

Commit 71e933f

Browse files
committed
Merge remote-tracking branch 'origin/master' into latex-new-output-panel
2 parents f9815c4 + 0ae2c0b commit 71e933f

File tree

9 files changed

+47
-71
lines changed

9 files changed

+47
-71
lines changed

src/packages/frontend/client/project.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,14 +279,14 @@ export class ProjectClient {
279279
compute_server_id: opts.compute_server_id ?? 0,
280280
service: EXEC_STREAM_SERVICE,
281281
});
282-
283282
let lastSeq = -1;
284283

285284
const req = cn.requestMany(
286285
subject,
287286
{ ...opts, debug },
288287
{
289288
maxWait: (opts.timeout ?? 300) * 1000,
289+
waitForInterest: true,
290290
},
291291
);
292292
for await (const resp of await req) {

src/packages/frontend/compute/compute-server.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Button, Card, Divider, Modal, Popconfirm, Spin } from "antd";
2-
import { CSSProperties, useMemo, useState } from "react";
3-
4-
import { useTypedRedux } from "@cocalc/frontend/app-framework";
2+
import { CSSProperties, useEffect, useMemo, useState } from "react";
3+
import { redux, useTypedRedux } from "@cocalc/frontend/app-framework";
54
import { Icon } from "@cocalc/frontend/components";
65
import ShowError from "@cocalc/frontend/components/error";
76
import { CancelText } from "@cocalc/frontend/i18n/components";
@@ -564,6 +563,13 @@ export default function ComputeServer({
564563
}
565564

566565
export function useServer({ id, project_id }) {
566+
useEffect(() => {
567+
const actions = redux.getProjectActions(project_id);
568+
actions.incrementReferenceCount();
569+
return () => {
570+
actions.decrementReferenceCount();
571+
};
572+
}, [project_id]);
567573
const computeServers = useTypedRedux({ project_id }, "compute_servers");
568574
const server = useMemo(() => {
569575
return computeServers?.get(`${id}`)?.toJS();

src/packages/frontend/compute/spend-limit.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,11 @@ export function SpendLimit({
4444
const [error, setError] = useState<string>("");
4545
const [saving, setSaving] = useState<boolean>(false);
4646
const [spendLimit, setSpendLimit] = useState<Partial<ISpendLimit>>(
47-
server.configuration?.spendLimit ?? SPEND_LIMIT_DEFAULTS,
47+
server?.configuration?.spendLimit ?? SPEND_LIMIT_DEFAULTS,
4848
);
49+
useEffect(() => {
50+
setSpendLimit(server?.configuration?.spendLimit ?? SPEND_LIMIT_DEFAULTS);
51+
}, [server?.configuration]);
4952

5053
if (server == null) {
5154
return <Spin />;
@@ -197,6 +200,7 @@ export function SpendLimitModal({ id, project_id, close, extra = [] }) {
197200
</div>
198201
}
199202
>
203+
{help && <div>Configure limits on spending here.</div>}
200204
<SpendLimit id={id} project_id={project_id} help={help} extra={extra} />
201205
</Modal>
202206
);

src/packages/frontend/frame-editors/generic/client.ts

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,16 @@
77
Typescript async/await rewrite of @cocalc/util/client.coffee...
88
*/
99

10-
import { Modal } from "antd";
1110
import { Map } from "immutable";
12-
1311
import { redux } from "@cocalc/frontend/app-framework";
14-
import { excludeFromComputeServer } from "@cocalc/frontend/file-associations";
1512
import { webapp_client } from "@cocalc/frontend/webapp-client";
1613
import { CompressedPatch } from "@cocalc/sync/editor/generic/types";
1714
import { callback2 } from "@cocalc/util/async-utils";
1815
import { Config as FormatterConfig } from "@cocalc/util/code-formatter";
19-
import { type UserSearchResult as User } from "@cocalc/util/db-schema/accounts";
2016
import { FakeSyncstring } from "./syncstring-fake";
17+
import { type UserSearchResult as User } from "@cocalc/util/db-schema/accounts";
2118
export { type User };
19+
import { excludeFromComputeServer } from "@cocalc/frontend/file-associations";
2220

2321
import type { ExecOpts, ExecOutput } from "@cocalc/util/db-schema/projects";
2422
export type { ExecOpts, ExecOutput };
@@ -27,40 +25,6 @@ import * as schema from "@cocalc/util/schema";
2725

2826
import { DEFAULT_FONT_SIZE } from "@cocalc/util/db-schema";
2927

30-
// Track which projects have already shown the restart dialog
31-
const shownRestartDialogs = new Set<string>();
32-
33-
export function showProjectRestartDialog(project_id: string): void {
34-
// Only show the dialog once per project
35-
if (shownRestartDialogs.has(project_id)) {
36-
return;
37-
}
38-
39-
shownRestartDialogs.add(project_id);
40-
41-
const actions = redux.getActions("projects");
42-
43-
Modal.confirm({
44-
title: "Project Needs Update",
45-
content: `This project needs to be restarted to support the new streaming compilation feature.
46-
Your work is automatically saved and will not be lost.`,
47-
okText: "Restart Project",
48-
cancelText: "Not Now",
49-
width: 500,
50-
onOk: () => {
51-
if (actions) {
52-
actions.restart_project(project_id);
53-
}
54-
// Clear the tracking when user clicks OK
55-
shownRestartDialogs.delete(project_id);
56-
},
57-
onCancel: () => {
58-
// Clear the tracking when user dismisses the dialog
59-
shownRestartDialogs.delete(project_id);
60-
},
61-
});
62-
}
63-
6428
export function server_time(): Date {
6529
return webapp_client.time_client.server_time();
6630
}

src/packages/frontend/frame-editors/jupyter-editor/editor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ const JUPYTER_MENUS = {
456456
icon: "dot-circle",
457457
label: ({ props }) => {
458458
const actions = props.actions.jupyter_actions;
459-
const store = actions.store;
459+
const store = actions?.store;
460460
if (!store) {
461461
return "Kernels";
462462
}
@@ -477,7 +477,7 @@ const JUPYTER_MENUS = {
477477
name: "kernels",
478478
children: ({ props }) => {
479479
const actions = props.actions.jupyter_actions;
480-
const store = actions.store;
480+
const store = actions?.store;
481481
if (!store) {
482482
return [];
483483
}

src/packages/frontend/frame-editors/latex-editor/util.ts

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55

66
// data and functions specific to the latex editor.
77

8-
import {
9-
ExecOutput,
10-
showProjectRestartDialog,
11-
} from "@cocalc/frontend/frame-editors/generic/client";
8+
import { ExecOutput } from "@cocalc/frontend/frame-editors/generic/client";
129
import { webapp_client } from "@cocalc/frontend/webapp-client";
1310
import { ExecOptsBlocking } from "@cocalc/util/db-schema/projects";
1411
import { separate_file_extension } from "@cocalc/util/misc";
@@ -171,17 +168,7 @@ export async function runJob(opts: RunJobOpts): Promise<ExecOutput> {
171168
});
172169

173170
stream.on("error", (err) => {
174-
// Check if this is a 503 error (exec-stream service not available in old project)
175-
if (err?.code === 503) {
176-
showProjectRestartDialog(project_id);
177-
reject(err);
178-
} else {
179-
reject(
180-
new Error(
181-
"Unable to run the compilation. Please check up on the project.",
182-
),
183-
);
184-
}
171+
reject(new Error(`Unable to run the compilation. ${err}`));
185172
});
186173
});
187174
}

src/packages/frontend/frame-editors/rmd-editor/utils.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44
*/
55

66
import { join } from "path";
7-
87
import { webapp_client } from "@cocalc/frontend/webapp-client";
98
import { change_filename_extension, path_split } from "@cocalc/util/misc";
109
import { ExecuteCodeOutputAsync } from "@cocalc/util/types/execute-code";
11-
import { ExecOutput, showProjectRestartDialog } from "../generic/client";
10+
import { ExecOutput } from "../generic/client";
1211

1312
// something in the rmarkdown source code replaces all spaces by dashes
1413
// [hsy] I think this is because of calling pandoc.
@@ -158,13 +157,7 @@ export async function runJob(opts: RunJobOpts): Promise<ExecOutput> {
158157
});
159158

160159
stream.on("error", (err) => {
161-
// Check if this is a 503 error (exec-stream service not available in old project)
162-
if (err?.code === 503) {
163-
showProjectRestartDialog(project_id);
164-
reject(err);
165-
} else {
166-
reject(err);
167-
}
160+
reject(err);
168161
});
169162
});
170163
}

src/packages/frontend/project_actions.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,9 +336,31 @@ export class ProjectActions extends Actions<ProjectStoreState> {
336336
};
337337
isTabClosed = () => !this.isTabOpened();
338338

339+
// The expensive part of the actions should NOT exist if and only if
340+
// the reference count is 0 *AND* the tab is closed.
341+
private referenceCount = 0;
342+
343+
incrementReferenceCount = () => {
344+
this.referenceCount++;
345+
this.initExpensive();
346+
};
347+
348+
decrementReferenceCount = () => {
349+
if (this.referenceCount <= 0) {
350+
console.warn(
351+
"BUG: attempt to decrement project actions reference count below 0",
352+
);
353+
return;
354+
}
355+
this.referenceCount--;
356+
if (this.referenceCount <= 0 && !this.isTabOpened()) {
357+
this.closeExpensive();
358+
}
359+
};
360+
339361
private expensiveLoop = async () => {
340362
while (this.state != "closed") {
341-
if (this.isTabOpened()) {
363+
if (this.isTabOpened() || this.referenceCount > 0) {
342364
this.initExpensive();
343365
} else {
344366
this.closeExpensive();

src/packages/util/smc-version.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
/* autogenerated by the update_version script */
2-
exports.version=1758034770;
2+
exports.version=1758657266;

0 commit comments

Comments
 (0)