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:
@@ -24,6 +24,7 @@ import pickBy from 'lodash/pickBy';
|
||||
import omit from 'lodash/omit';
|
||||
import { writeFileWithLock } from '../shared/utils';
|
||||
import { ScheduleType } from '../interface/schedule';
|
||||
import { logStreamManager } from '../shared/logStreamManager';
|
||||
|
||||
@Service()
|
||||
export default class CronService {
|
||||
@@ -516,7 +517,7 @@ export default class CronService {
|
||||
{ where: { id } },
|
||||
);
|
||||
cp.stdout.on('data', async (data) => {
|
||||
await fs.appendFile(absolutePath, data.toString());
|
||||
await logStreamManager.write(absolutePath, data.toString());
|
||||
});
|
||||
cp.stderr.on('data', async (data) => {
|
||||
this.logger.info(
|
||||
@@ -524,7 +525,7 @@ export default class CronService {
|
||||
command,
|
||||
data.toString(),
|
||||
);
|
||||
await fs.appendFile(absolutePath, data.toString());
|
||||
await logStreamManager.write(absolutePath, data.toString());
|
||||
});
|
||||
cp.on('error', async (err) => {
|
||||
this.logger.error(
|
||||
@@ -532,7 +533,7 @@ export default class CronService {
|
||||
command,
|
||||
err,
|
||||
);
|
||||
await fs.appendFile(absolutePath, JSON.stringify(err));
|
||||
await logStreamManager.write(absolutePath, JSON.stringify(err));
|
||||
});
|
||||
|
||||
cp.on('exit', async (code) => {
|
||||
@@ -541,6 +542,8 @@ export default class CronService {
|
||||
JSON.stringify(params),
|
||||
code,
|
||||
);
|
||||
// Close the stream after task completion
|
||||
await logStreamManager.closeStream(absolutePath);
|
||||
await CrontabModel.update(
|
||||
{ status: CrontabStatus.idle, pid: undefined },
|
||||
{ where: { id } },
|
||||
|
||||
Reference in New Issue
Block a user