mirror of
https://github.com/whyour/qinglong.git
synced 2026-06-30 20:35:09 +08:00
修复订阅执行日志输出
This commit is contained in:
@@ -27,6 +27,7 @@ export interface TaskCallbacks {
|
||||
endTime: dayjs.Dayjs,
|
||||
diff: number,
|
||||
) => void;
|
||||
onLog?: (message: string) => void;
|
||||
onError?: (message: string) => void;
|
||||
}
|
||||
|
||||
@@ -48,9 +49,13 @@ export default class ScheduleService {
|
||||
|
||||
callbacks.onStart?.(cp, startTime);
|
||||
|
||||
cp.stdout.on('data', (data) => {
|
||||
callbacks.onLog?.(data.toString());
|
||||
});
|
||||
|
||||
cp.stderr.on('data', (data) => {
|
||||
this.logger.error(
|
||||
'执行任务%s失败,时间:%s, 错误信息:%j',
|
||||
'执行任务 %s 失败,时间:%s, 错误信息:%j',
|
||||
command,
|
||||
new Date().toLocaleString(),
|
||||
data.toString(),
|
||||
@@ -60,7 +65,7 @@ export default class ScheduleService {
|
||||
|
||||
cp.on('error', (err) => {
|
||||
this.logger.error(
|
||||
'执行任务%s失败,时间:%s, 错误信息:%j',
|
||||
'创建任务 %s 失败,时间:%s, 错误信息:%j',
|
||||
command,
|
||||
new Date().toLocaleString(),
|
||||
err,
|
||||
|
||||
@@ -181,6 +181,11 @@ export default class SubscriptionService {
|
||||
const absolutePath = await this.handleLogPath(sub.log_path as string);
|
||||
fs.appendFileSync(absolutePath, `\n${message}`);
|
||||
},
|
||||
onLog: async (message: string) => {
|
||||
const sub = await this.getDb({ id: doc.id });
|
||||
const absolutePath = await this.handleLogPath(sub.log_path as string);
|
||||
fs.appendFileSync(absolutePath, `\n${message}`);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user