querysub 0.240.0 → 0.242.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,
|
|
@@ -95,21 +100,19 @@ export async function streamScreenOutput(config: {
|
|
|
95
100
|
const captureCommand = `${prefix}tmux capture-pane -p -S -2000 -t ${screenName}`;
|
|
96
101
|
// Initial data
|
|
97
102
|
const initialContent = await runPromise(captureCommand, { quiet: true });
|
|
98
|
-
console.log(green(`Callback to onDataWrapped ${screenName} ${initialContent.length}`));
|
|
99
103
|
if (initialContent) {
|
|
100
104
|
await onDataWrapped(initialContent);
|
|
101
105
|
}
|
|
102
|
-
console.log(green(`After callback to onDataWrapped ${screenName} ${initialContent.length}`));
|
|
103
106
|
|
|
104
|
-
|
|
105
|
-
|
|
107
|
+
const pipeFile = `${root}${screenName}/pipe.txt`;
|
|
108
|
+
|
|
109
|
+
// Use tail -f to follow the pipe file
|
|
110
|
+
childProcess = spawn(`tail`, ["-F", pipeFile], {
|
|
106
111
|
stdio: "pipe",
|
|
107
112
|
});
|
|
108
113
|
|
|
109
114
|
let started = new PromiseObj<void>();
|
|
110
115
|
|
|
111
|
-
console.log(green(`Has stdout: ${!!childProcess.stdout}`));
|
|
112
|
-
|
|
113
116
|
childProcess.stdout?.on("data", (data) => {
|
|
114
117
|
if (stopped) return;
|
|
115
118
|
console.log(`Captured data for ${screenName}: ${data.length}`);
|
|
@@ -296,6 +299,31 @@ ${config.command}
|
|
|
296
299
|
`;
|
|
297
300
|
await fs.promises.writeFile(config.folder + "../command.sh", command);
|
|
298
301
|
await runPromise(`${prefix}tmux send-keys -t ${screenName} 'bash ../command.sh' Enter`);
|
|
302
|
+
|
|
303
|
+
// Setup pipe-pane as well
|
|
304
|
+
|
|
305
|
+
let pipeFile = path.resolve(config.folder + "../pipe.txt");
|
|
306
|
+
let pipeScript = path.resolve(config.folder + "../pipe.sh");
|
|
307
|
+
await fs.promises.writeFile(pipeScript, `#!/bin/bash
|
|
308
|
+
line_count=0
|
|
309
|
+
while IFS= read -r line; do
|
|
310
|
+
echo "$line" >> "${pipeFile}"
|
|
311
|
+
((line_count++))
|
|
312
|
+
|
|
313
|
+
# Check file size every 100 lines to avoid too much overhead
|
|
314
|
+
if (( line_count % ${PIPE_FILE_LINE_LIMIT} == 0 )); then
|
|
315
|
+
if [ -f "${pipeFile}" ]; then
|
|
316
|
+
# Get file size (works on both Linux and macOS)
|
|
317
|
+
filesize=$(stat -f%z "${pipeFile}" 2>/dev/null || stat -c%s "${pipeFile}" 2>/dev/null || echo 0)
|
|
318
|
+
if [ "$filesize" -gt 1048576 ]; then
|
|
319
|
+
# Keep only the last 1000 lines when file gets too big
|
|
320
|
+
tail -n ${PIPE_FILE_LINE_LIMIT} "${pipeFile}" > "${pipeFile}.tmp" && mv "${pipeFile}.tmp" "${pipeFile}"
|
|
321
|
+
fi
|
|
322
|
+
fi
|
|
323
|
+
fi
|
|
324
|
+
done`);
|
|
325
|
+
await runPromise(`chmod +x ${pipeScript}`);
|
|
326
|
+
await runPromise(`${prefix}tmux pipe-pane -t ${screenName} 'bash ${pipeScript}'`);
|
|
299
327
|
});
|
|
300
328
|
const killScreen = measureWrap(async function killScreen(config: {
|
|
301
329
|
screenName: string;
|
|
@@ -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
|
|
|
@@ -14,7 +14,8 @@ export async function runPromise(command: string, config?: {
|
|
|
14
14
|
const childProc = child_process.spawn(command, {
|
|
15
15
|
shell: true,
|
|
16
16
|
cwd: config?.cwd,
|
|
17
|
-
|
|
17
|
+
// NOTE: Now we pipe stdin, as I think inheriting it was causing us to block sometimes?
|
|
18
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
18
19
|
});
|
|
19
20
|
|
|
20
21
|
let fullOutput = "";
|