mirror of
https://github.com/whyour/qinglong.git
synced 2026-12-01 01:39:52 +08:00
fix: preserve task logs and refine editor controls
This commit is contained in:
1 parent
4b3c31c0a7
commit
a65d56a980
10 files changed
+356
-49
No files matched your search
+12
-3
@@ -1007,8 +1007,15 @@ export default class CronService {
|
||||
return;
|
||||
}
|
||||
}
|
||||
const launchCommand = `real_log_path=${shellValue(logPath)} no_delay=true ${this.makeCommand(cron, true)}`;
|
||||
// Let the independent supervisor own the log, while the command keeps
|
||||
// writing to a drained pipe even if the worker dies or the log fills up.
|
||||
const supervisedLog = Boolean(triggerId && outputPath);
|
||||
const cp = spawnCronCommand(
|
||||
`real_log_path=${shellValue(logPath)} no_delay=true ${this.makeCommand(cron, true)}`, triggerId,
|
||||
launchCommand,
|
||||
triggerId,
|
||||
undefined,
|
||||
outputPath,
|
||||
);
|
||||
// Install observers before the first await: very short children may already exit.
|
||||
const { completed } = observeChildProcess(cp, {
|
||||
@@ -1051,8 +1058,10 @@ export default class CronService {
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
onStdout: outputPath ? (message) => logStreamManager.write(outputPath, message) : undefined,
|
||||
onStderr: outputPath ? (message) => logStreamManager.write(outputPath, message) : undefined,
|
||||
onStdout: outputPath && !supervisedLog ? (message) => logStreamManager.write(outputPath, message) : undefined,
|
||||
onStderr: supervisedLog
|
||||
? async (message) => { this.logger.error('[panel][Command supervisor] Task ID: %s, %s', id, message.trim()); }
|
||||
: outputPath ? (message) => logStreamManager.write(outputPath, message) : undefined,
|
||||
});
|
||||
const result = await completed;
|
||||
state = result.signal ? 'stopped' : result.error || result.code !== 0 ? 'failed' : 'finished';
|
||||
|
||||
@@ -7,7 +7,7 @@ import type { Readable } from 'stream';
|
||||
|
||||
// A managed command waits on its parent's pipe. EOF before authorization exits
|
||||
// without interpreting the command, even when the worker is killed by SIGKILL.
|
||||
export function spawnCronCommand(command: string, triggerId?: string, onCommandStart?: (at: number) => void) {
|
||||
export function spawnCronCommand(command: string, triggerId?: string, onCommandStart?: (at: number) => void, outputPath?: string) {
|
||||
if (!triggerId) return spawn(command, { shell: '/bin/bash' });
|
||||
const sourceScript = join(__dirname, '../../shell/cron-command.py');
|
||||
const supervisor = existsSync(sourceScript) ? sourceScript : join(process.env.QL_DIR!, 'shell/cron-command.py');
|
||||
@@ -15,6 +15,7 @@ export function spawnCronCommand(command: string, triggerId?: string, onCommandS
|
||||
receiptPath(triggerId) || '', process.execPath, join(__dirname, 'managedExit.cjs'),
|
||||
];
|
||||
if (onCommandStart) args.push('report-start');
|
||||
if (outputPath) args.push('log-output', outputPath);
|
||||
const child = spawn('python3', args, { env: { ...process.env, QL_TRIGGER_ID: triggerId },
|
||||
stdio: onCommandStart ? ['pipe', 'pipe', 'pipe', 'pipe'] : 'pipe' }) as ChildProcessWithoutNullStreams;
|
||||
if (onCommandStart && child.stdio[3]) {
|
||||
|
||||
Reference in new issue
Block a user