From 6b4ca7929332075f59b845a6e5cab9059b1e22e5 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 8 Nov 2025 17:23:59 +0000 Subject: [PATCH] Add log_name field to enable custom log folder naming Co-authored-by: whyour <22700758+whyour@users.noreply.github.com> --- back/data/cron.ts | 3 +++ back/services/cron.ts | 4 ++-- back/validation/schedule.ts | 1 + src/locales/en-US.json | 5 ++++- src/locales/zh-CN.json | 5 ++++- src/pages/crontab/modal.tsx | 9 +++++++++ 6 files changed, 23 insertions(+), 4 deletions(-) diff --git a/back/data/cron.ts b/back/data/cron.ts index b234d59c..c75707a3 100644 --- a/back/data/cron.ts +++ b/back/data/cron.ts @@ -21,6 +21,7 @@ export class Crontab { extra_schedules?: Array<{ schedule: string }>; task_before?: string; task_after?: string; + log_name?: string; constructor(options: Crontab) { this.name = options.name; @@ -45,6 +46,7 @@ export class Crontab { this.extra_schedules = options.extra_schedules; this.task_before = options.task_before; this.task_after = options.task_after; + this.log_name = options.log_name; } } @@ -84,4 +86,5 @@ export const CrontabModel = sequelize.define('Crontab', { extra_schedules: DataTypes.JSON, task_before: DataTypes.STRING, task_after: DataTypes.STRING, + log_name: DataTypes.STRING, }); diff --git a/back/services/cron.ts b/back/services/cron.ts index a838ce9e..380428a3 100644 --- a/back/services/cron.ts +++ b/back/services/cron.ts @@ -476,8 +476,8 @@ export default class CronService { `[panel][开始执行任务] 参数: ${JSON.stringify(params)}`, ); - let { id, command, log_path } = cron; - const uniqPath = await getUniqPath(command, `${id}`); + let { id, command, log_path, log_name } = cron; + const uniqPath = log_name || (await getUniqPath(command, `${id}`)); const logTime = dayjs().format('YYYY-MM-DD-HH-mm-ss-SSS'); const logDirPath = path.resolve(config.logPath, `${uniqPath}`); if (log_path?.split('/')?.every((x) => x !== uniqPath)) { diff --git a/back/validation/schedule.ts b/back/validation/schedule.ts index a280156a..f8a503b8 100644 --- a/back/validation/schedule.ts +++ b/back/validation/schedule.ts @@ -37,4 +37,5 @@ export const commonCronSchema = { extra_schedules: Joi.array().optional().allow(null), task_before: Joi.string().optional().allow('').allow(null), task_after: Joi.string().optional().allow('').allow(null), + log_name: Joi.string().optional().allow('').allow(null), }; diff --git a/src/locales/en-US.json b/src/locales/en-US.json index 9a21ef3a..9b7d1ad7 100644 --- a/src/locales/en-US.json +++ b/src/locales/en-US.json @@ -521,5 +521,8 @@ "远程仓库缓存": "Remote repository cache", "SSH 文件缓存": "SSH file cache", "清除依赖缓存": "Clean dependency cache", - "清除成功": "Clean successful" + "清除成功": "Clean successful", + "日志名称": "Log Name", + "自定义日志文件夹名称,用于区分不同任务的日志,留空则自动生成": "Custom log folder name to distinguish logs from different tasks. Leave blank to auto-generate", + "请输入自定义日志文件夹名称": "Please enter a custom log folder name" } diff --git a/src/locales/zh-CN.json b/src/locales/zh-CN.json index c19d6984..42788752 100644 --- a/src/locales/zh-CN.json +++ b/src/locales/zh-CN.json @@ -521,5 +521,8 @@ "远程仓库缓存": "远程仓库缓存", "SSH 文件缓存": "SSH 文件缓存", "清除依赖缓存": "清除依赖缓存", - "清除成功": "清除成功" + "清除成功": "清除成功", + "日志名称": "日志名称", + "自定义日志文件夹名称,用于区分不同任务的日志,留空则自动生成": "自定义日志文件夹名称,用于区分不同任务的日志,留空则自动生成", + "请输入自定义日志文件夹名称": "请输入自定义日志文件夹名称" } diff --git a/src/pages/crontab/modal.tsx b/src/pages/crontab/modal.tsx index 6a7c0492..7f87f427 100644 --- a/src/pages/crontab/modal.tsx +++ b/src/pages/crontab/modal.tsx @@ -180,6 +180,15 @@ const CronModal = ({ + + +