Skip to content

Commit d350699

Browse files
committed
add command to stop (not kill) the server
1 parent c29036a commit d350699

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

src/execute/julia.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -858,11 +858,19 @@ function populateJuliaEngineCommand(command: Command) {
858858
"Prints the julia server log file if it exists which can be used to diagnose problems.",
859859
)
860860
.action(printJuliaServerLog)
861-
.command("close", "Close the worker for a given notebook")
861+
.command(
862+
"close",
863+
"Close the worker for a given notebook. If it is currently running, it will not be interrupted.",
864+
)
862865
.arguments("<file:string>")
863866
.action(async (_, file) => {
864867
await closeWorker(file);
865-
});
868+
})
869+
.command("stop", "Stop the server")
870+
.description(
871+
"Sends a message to the server that it should stop all notebooks and itself. Running notebooks will not be interrupted.",
872+
)
873+
.action(stopServer);
866874
return;
867875
}
868876

@@ -961,3 +969,11 @@ async function closeWorker(file: string) {
961969
});
962970
info("Worker closed successfully.");
963971
}
972+
973+
async function stopServer() {
974+
const result = await connectAndWriteJuliaCommandToRunningServer({
975+
type: "stop",
976+
content: {},
977+
});
978+
info(result.message);
979+
}

tests/smoke/call/engine/julia/julia.test.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { assert, assertStringIncludes } from "testing/asserts";
22
import { docs, quartoDevCmd } from "../../../../utils.ts";
33
import { existsSync } from "fs/exists";
44
import { juliaServerLogFile, juliaTransportFile } from "../../../../../src/execute/julia.ts";
5+
import { sleep } from "../../../../../src/core/wait.ts";
56

67
const sleepQmd = docs("call/engine/julia/sleep.qmd");
78
assert(existsSync(sleepQmd));
@@ -104,4 +105,22 @@ Deno.test("log exists", () => {
104105
).outputSync();
105106
assertSuccess(log_output);
106107
assertStdoutIncludes(log_output, "Log started at");
107-
});
108+
});
109+
110+
Deno.test("stop the idling server", async () => {
111+
const stop_output = new Deno.Command(
112+
quartoDevCmd(),
113+
{args: ["call", "engine", "julia", "stop"]}
114+
).outputSync();
115+
assertSuccess(stop_output);
116+
assertStderrIncludes(stop_output, "Server stopped");
117+
118+
await sleep(2000); // allow a little bit of time for the server to stop and the log message to be written
119+
120+
const log_output = new Deno.Command(
121+
quartoDevCmd(),
122+
{args: ["call", "engine", "julia", "log"]}
123+
).outputSync();
124+
assertSuccess(log_output);
125+
assertStdoutIncludes(log_output, "Server stopped");
126+
});

0 commit comments

Comments
 (0)