mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-23 23:06:06 +08:00
修复任务运行错误时没有日志,修改 tooltip 样式
This commit is contained in:
parent
ac904cae61
commit
0b9066525a
|
@ -5,7 +5,7 @@ import { Crontab, CrontabModel, CrontabStatus } from '../data/cron';
|
||||||
import { exec, execSync } from 'child_process';
|
import { exec, execSync } from 'child_process';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import cron_parser from 'cron-parser';
|
import cron_parser from 'cron-parser';
|
||||||
import { getFileContentByName, fileExist, killTask } from '../config/util';
|
import { getFileContentByName, fileExist, killTask, getUniqPath } from '../config/util';
|
||||||
import { promises, existsSync } from 'fs';
|
import { promises, existsSync } from 'fs';
|
||||||
import { Op, where, col as colFn, FindOptions, fn } from 'sequelize';
|
import { Op, where, col as colFn, FindOptions, fn } from 'sequelize';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
@ -13,10 +13,11 @@ import { TASK_PREFIX, QL_PREFIX } from '../config/const';
|
||||||
import cronClient from '../schedule/client';
|
import cronClient from '../schedule/client';
|
||||||
import taskLimit from '../shared/pLimit';
|
import taskLimit from '../shared/pLimit';
|
||||||
import { spawn } from 'cross-spawn';
|
import { spawn } from 'cross-spawn';
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class CronService {
|
export default class CronService {
|
||||||
constructor(@Inject('logger') private logger: winston.Logger) {}
|
constructor(@Inject('logger') private logger: winston.Logger) { }
|
||||||
|
|
||||||
private isSixCron(cron: Crontab) {
|
private isSixCron(cron: Crontab) {
|
||||||
const { schedule } = cron;
|
const { schedule } = cron;
|
||||||
|
@ -391,8 +392,14 @@ export default class CronService {
|
||||||
}
|
}
|
||||||
|
|
||||||
let { id, command, log_path } = cron;
|
let { id, command, log_path } = cron;
|
||||||
const absolutePath = path.resolve(config.logPath, `${log_path}`);
|
const uniqPath = await getUniqPath(command);
|
||||||
const logFileExist = log_path && (await fileExist(absolutePath));
|
const logTime = dayjs().format('YYYY-MM-DD-HH-mm-ss-SSS');
|
||||||
|
const logDirPath = path.resolve(config.logPath, `${uniqPath}`);
|
||||||
|
if (!log_path?.includes(uniqPath)) {
|
||||||
|
fs.mkdirSync(logDirPath, { recursive: true });
|
||||||
|
}
|
||||||
|
const logPath = `${uniqPath}/${logTime}.log`;
|
||||||
|
const absolutePath = path.resolve(config.logPath, `${logPath}`);
|
||||||
|
|
||||||
this.logger.silly('Running job');
|
this.logger.silly('Running job');
|
||||||
this.logger.silly('ID: ' + id);
|
this.logger.silly('ID: ' + id);
|
||||||
|
@ -412,21 +419,17 @@ export default class CronService {
|
||||||
cmdStr = `${cmdStr} now`;
|
cmdStr = `${cmdStr} now`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const cp = spawn(`ID=${id} ${cmdStr}`, { shell: '/bin/bash' });
|
const cp = spawn(`real_log_path=${logPath} ID=${id} ${cmdStr}`, { shell: '/bin/bash' });
|
||||||
|
|
||||||
await CrontabModel.update(
|
await CrontabModel.update(
|
||||||
{ status: CrontabStatus.running, pid: cp.pid },
|
{ status: CrontabStatus.running, pid: cp.pid, log_path: logPath },
|
||||||
{ where: { id } },
|
{ where: { id } },
|
||||||
);
|
);
|
||||||
cp.stderr.on('data', (data) => {
|
cp.stderr.on('data', (data) => {
|
||||||
if (logFileExist) {
|
fs.appendFileSync(`${absolutePath}`, `${data.toString()}`);
|
||||||
fs.appendFileSync(`${absolutePath}`, `${data.toString()}`);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
cp.on('error', (err) => {
|
cp.on('error', (err) => {
|
||||||
if (logFileExist) {
|
fs.appendFileSync(`${absolutePath}`, `${JSON.stringify(err)}`);
|
||||||
fs.appendFileSync(`${absolutePath}`, `${JSON.stringify(err)}`);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
cp.on('exit', async (code, signal) => {
|
cp.on('exit', async (code, signal) => {
|
||||||
|
|
|
@ -93,10 +93,12 @@ body {
|
||||||
}
|
}
|
||||||
|
|
||||||
.ant-tooltip {
|
.ant-tooltip {
|
||||||
max-width: 500px !important;
|
max-width: 300px !important;
|
||||||
|
|
||||||
.ant-tooltip-inner {
|
.ant-tooltip-inner {
|
||||||
word-break: break-all !important;
|
word-break: break-all !important;
|
||||||
|
max-height: 300px !important;
|
||||||
|
overflow-y: auto !important;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,7 +69,7 @@ const Crontab = () => {
|
||||||
dataIndex: 'name',
|
dataIndex: 'name',
|
||||||
key: 'name',
|
key: 'name',
|
||||||
fixed: 'left',
|
fixed: 'left',
|
||||||
width: 140,
|
width: 120,
|
||||||
render: (text: string, record: any) => (
|
render: (text: string, record: any) => (
|
||||||
<>
|
<>
|
||||||
<a
|
<a
|
||||||
|
@ -124,7 +124,7 @@ const Crontab = () => {
|
||||||
title: intl.get('命令/脚本'),
|
title: intl.get('命令/脚本'),
|
||||||
dataIndex: 'command',
|
dataIndex: 'command',
|
||||||
key: 'command',
|
key: 'command',
|
||||||
width: 220,
|
width: 240,
|
||||||
render: (text, record) => {
|
render: (text, record) => {
|
||||||
return (
|
return (
|
||||||
<Paragraph
|
<Paragraph
|
||||||
|
|
6
src/pages/env/index.tsx
vendored
6
src/pages/env/index.tsx
vendored
|
@ -91,11 +91,7 @@ const Env = () => {
|
||||||
render: (text: string, record: any) => {
|
render: (text: string, record: any) => {
|
||||||
return (
|
return (
|
||||||
<div style={{ display: 'flex', alignItems: 'center' }}>
|
<div style={{ display: 'flex', alignItems: 'center' }}>
|
||||||
<Tooltip
|
<Tooltip title={text} placement="topLeft">
|
||||||
title={text}
|
|
||||||
placement="topLeft"
|
|
||||||
overlayInnerStyle={{ maxHeight: 400, overflowY: 'auto' }}
|
|
||||||
>
|
|
||||||
<div className="text-ellipsis">{text}</div>
|
<div className="text-ellipsis">{text}</div>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
<Copy text={text} />
|
<Copy text={text} />
|
||||||
|
|
Loading…
Reference in New Issue
Block a user