mirror of
https://github.com/whyour/qinglong.git
synced 2026-07-01 04:40:38 +08:00
Optimize log file writes using stream pooling (#2835)
* Initial plan * Implement LogStreamManager for optimized log writing Co-authored-by: whyour <22700758+whyour@users.noreply.github.com> * Fix error handler in LogStreamManager to avoid race conditions Co-authored-by: whyour <22700758+whyour@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: whyour <22700758+whyour@users.noreply.github.com>
This commit is contained in:
+5
-2
@@ -14,6 +14,7 @@ import {
|
||||
} from '../config/util';
|
||||
import dayjs from 'dayjs';
|
||||
import multer from 'multer';
|
||||
import { logStreamManager } from '../shared/logStreamManager';
|
||||
|
||||
const route = Router();
|
||||
const storage = multer.diskStorage({
|
||||
@@ -276,17 +277,19 @@ export default (app: Router) => {
|
||||
res.setHeader('QL-Task-Log', `${logPath}`);
|
||||
},
|
||||
onEnd: async (cp, endTime, diff) => {
|
||||
// Close the stream after task completion
|
||||
await logStreamManager.closeStream(await handleLogPath(logPath));
|
||||
res.end();
|
||||
},
|
||||
onError: async (message: string) => {
|
||||
res.write(message);
|
||||
const absolutePath = await handleLogPath(logPath);
|
||||
await fs.appendFile(absolutePath, message);
|
||||
await logStreamManager.write(absolutePath, message);
|
||||
},
|
||||
onLog: async (message: string) => {
|
||||
res.write(message);
|
||||
const absolutePath = await handleLogPath(logPath);
|
||||
await fs.appendFile(absolutePath, message);
|
||||
await logStreamManager.write(absolutePath, message);
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user