From 0b9066525a5c2109a2a25230bfe2a24dd197d994 Mon Sep 17 00:00:00 2001 From: whyour Date: Thu, 24 Aug 2023 23:14:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BB=BB=E5=8A=A1=E8=BF=90?= =?UTF-8?q?=E8=A1=8C=E9=94=99=E8=AF=AF=E6=97=B6=E6=B2=A1=E6=9C=89=E6=97=A5?= =?UTF-8?q?=E5=BF=97=EF=BC=8C=E4=BF=AE=E6=94=B9=20tooltip=20=E6=A0=B7?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/services/cron.ts | 27 +++++++++++++++------------ src/layouts/index.less | 4 +++- src/pages/crontab/index.tsx | 4 ++-- src/pages/env/index.tsx | 6 +----- 4 files changed, 21 insertions(+), 20 deletions(-) diff --git a/back/services/cron.ts b/back/services/cron.ts index ca2908e7..a4da2c2e 100644 --- a/back/services/cron.ts +++ b/back/services/cron.ts @@ -5,7 +5,7 @@ import { Crontab, CrontabModel, CrontabStatus } from '../data/cron'; import { exec, execSync } from 'child_process'; import fs from 'fs'; 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 { Op, where, col as colFn, FindOptions, fn } from 'sequelize'; import path from 'path'; @@ -13,10 +13,11 @@ import { TASK_PREFIX, QL_PREFIX } from '../config/const'; import cronClient from '../schedule/client'; import taskLimit from '../shared/pLimit'; import { spawn } from 'cross-spawn'; +import dayjs from 'dayjs'; @Service() export default class CronService { - constructor(@Inject('logger') private logger: winston.Logger) {} + constructor(@Inject('logger') private logger: winston.Logger) { } private isSixCron(cron: Crontab) { const { schedule } = cron; @@ -391,8 +392,14 @@ export default class CronService { } let { id, command, log_path } = cron; - const absolutePath = path.resolve(config.logPath, `${log_path}`); - const logFileExist = log_path && (await fileExist(absolutePath)); + const uniqPath = await getUniqPath(command); + 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('ID: ' + id); @@ -412,21 +419,17 @@ export default class CronService { 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( - { status: CrontabStatus.running, pid: cp.pid }, + { status: CrontabStatus.running, pid: cp.pid, log_path: logPath }, { where: { id } }, ); cp.stderr.on('data', (data) => { - if (logFileExist) { - fs.appendFileSync(`${absolutePath}`, `${data.toString()}`); - } + fs.appendFileSync(`${absolutePath}`, `${data.toString()}`); }); cp.on('error', (err) => { - if (logFileExist) { - fs.appendFileSync(`${absolutePath}`, `${JSON.stringify(err)}`); - } + fs.appendFileSync(`${absolutePath}`, `${JSON.stringify(err)}`); }); cp.on('exit', async (code, signal) => { diff --git a/src/layouts/index.less b/src/layouts/index.less index 8569d568..ab1ddc44 100644 --- a/src/layouts/index.less +++ b/src/layouts/index.less @@ -93,10 +93,12 @@ body { } .ant-tooltip { - max-width: 500px !important; + max-width: 300px !important; .ant-tooltip-inner { word-break: break-all !important; + max-height: 300px !important; + overflow-y: auto !important; } } diff --git a/src/pages/crontab/index.tsx b/src/pages/crontab/index.tsx index e0a62c7c..a204c549 100644 --- a/src/pages/crontab/index.tsx +++ b/src/pages/crontab/index.tsx @@ -69,7 +69,7 @@ const Crontab = () => { dataIndex: 'name', key: 'name', fixed: 'left', - width: 140, + width: 120, render: (text: string, record: any) => ( <> { title: intl.get('命令/脚本'), dataIndex: 'command', key: 'command', - width: 220, + width: 240, render: (text, record) => { return ( { render: (text: string, record: any) => { return (
- +
{text}