querysub 0.241.0 → 0.243.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -23,6 +23,9 @@ import { blue, green, magenta, red } from "socket-function/src/formatting/logCol
|
|
|
23
23
|
import { shutdown } from "../diagnostics/periodic";
|
|
24
24
|
import { onServiceConfigChange } from "./machineController";
|
|
25
25
|
import { PromiseObj } from "../promise";
|
|
26
|
+
import path from "path";
|
|
27
|
+
|
|
28
|
+
const PIPE_FILE_LINE_LIMIT = 10;
|
|
26
29
|
|
|
27
30
|
const getLiveMachineInfo = measureWrap(async function getLiveMachineInfo() {
|
|
28
31
|
let machineInfo: MachineInfo = {
|
|
@@ -51,6 +54,8 @@ export async function streamScreenOutput(config: {
|
|
|
51
54
|
index: number;
|
|
52
55
|
onData: (data: string) => Promise<void>;
|
|
53
56
|
}) {
|
|
57
|
+
// Find the pipe file for this screen
|
|
58
|
+
const root = os.homedir() + "/" + SERVICE_FOLDER;
|
|
54
59
|
let screenName = getScreenName({
|
|
55
60
|
serviceKey: config.key,
|
|
56
61
|
index: config.index,
|
|
@@ -92,15 +97,10 @@ export async function streamScreenOutput(config: {
|
|
|
92
97
|
|
|
93
98
|
return (async () => {
|
|
94
99
|
try {
|
|
95
|
-
const
|
|
96
|
-
// Initial data
|
|
97
|
-
const initialContent = await runPromise(captureCommand, { quiet: true });
|
|
98
|
-
if (initialContent) {
|
|
99
|
-
await onDataWrapped(initialContent);
|
|
100
|
-
}
|
|
100
|
+
const pipeFile = `${root}${screenName}/pipe.txt`;
|
|
101
101
|
|
|
102
|
-
|
|
103
|
-
|
|
102
|
+
// Use tail -f to follow the pipe file
|
|
103
|
+
childProcess = spawn(`tail`, ["-f", pipeFile, "--retry", "--lines", "1000"], {
|
|
104
104
|
stdio: "pipe",
|
|
105
105
|
});
|
|
106
106
|
|
|
@@ -292,6 +292,31 @@ ${config.command}
|
|
|
292
292
|
`;
|
|
293
293
|
await fs.promises.writeFile(config.folder + "../command.sh", command);
|
|
294
294
|
await runPromise(`${prefix}tmux send-keys -t ${screenName} 'bash ../command.sh' Enter`);
|
|
295
|
+
|
|
296
|
+
// Setup pipe-pane as well
|
|
297
|
+
|
|
298
|
+
let pipeFile = path.resolve(config.folder + "../pipe.txt");
|
|
299
|
+
let pipeScript = path.resolve(config.folder + "../pipe.sh");
|
|
300
|
+
await fs.promises.writeFile(pipeScript, `#!/bin/bash
|
|
301
|
+
line_count=0
|
|
302
|
+
while IFS= read -r line; do
|
|
303
|
+
echo "$line" >> "${pipeFile}"
|
|
304
|
+
((line_count++))
|
|
305
|
+
|
|
306
|
+
# Check file size every 100 lines to avoid too much overhead
|
|
307
|
+
if (( line_count % ${PIPE_FILE_LINE_LIMIT} == 0 )); then
|
|
308
|
+
if [ -f "${pipeFile}" ]; then
|
|
309
|
+
# Get file size (works on both Linux and macOS)
|
|
310
|
+
filesize=$(stat -f%z "${pipeFile}" 2>/dev/null || stat -c%s "${pipeFile}" 2>/dev/null || echo 0)
|
|
311
|
+
if [ "$filesize" -gt 1048576 ]; then
|
|
312
|
+
# Keep only the last 1000 lines when file gets too big
|
|
313
|
+
tail -n ${PIPE_FILE_LINE_LIMIT} "${pipeFile}" > "${pipeFile}.tmp" && mv "${pipeFile}.tmp" "${pipeFile}"
|
|
314
|
+
fi
|
|
315
|
+
fi
|
|
316
|
+
fi
|
|
317
|
+
done`);
|
|
318
|
+
await runPromise(`chmod +x ${pipeScript}`);
|
|
319
|
+
await runPromise(`${prefix}tmux pipe-pane -t ${screenName} 'bash ${pipeScript}'`);
|
|
295
320
|
});
|
|
296
321
|
const killScreen = measureWrap(async function killScreen(config: {
|
|
297
322
|
screenName: string;
|
|
@@ -340,7 +365,7 @@ async function quickIsOutdated() {
|
|
|
340
365
|
let screen = screens.find(x => x.screenName === screenName);
|
|
341
366
|
if (!screen) return true;
|
|
342
367
|
|
|
343
|
-
let folder = root +
|
|
368
|
+
let folder = root + screenName + "/";
|
|
344
369
|
let parameterPath = folder + "/parameters.json";
|
|
345
370
|
if (!fs.existsSync(parameterPath)) return true;
|
|
346
371
|
let prevParameters = await fs.promises.readFile(parameterPath, "utf8");
|
|
@@ -5,7 +5,9 @@ Syncing isn't updating?
|
|
|
5
5
|
- Buttons per key + index, which we can figure out clientside. Stream results under the button, and we can stream multiple at once?
|
|
6
6
|
- OH, just for superusers, so the browser can connect directly!
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
2) Verify when the file is truncated it still works
|
|
9
|
+
|
|
10
|
+
3) OH! I think if something is scrollable, and is scrolled down, it'll stick to the bottom. We just need it to start scrollable!
|
|
9
11
|
|
|
10
12
|
4) Destroy our testing digital ocean server
|
|
11
13
|
|