diff --git a/app/run.py b/app/run.py index 64791a0..58c77b0 100644 --- a/app/run.py +++ b/app/run.py @@ -25,6 +25,8 @@ import base64 import sys import os import re +import random +import time parent_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) sys.path.insert(0, parent_dir) @@ -683,6 +685,18 @@ def add_task(): # 定时任务执行的函数 def run_python(args): logging.info(f">>> 定时运行任务") + # 检查是否需要随机延迟执行 + if delay := config_data.get("crontab_delay"): + try: + delay_seconds = int(delay) + if delay_seconds > 0: + # 在0到设定值之间随机选择一个延迟时间 + random_delay = random.randint(0, delay_seconds) + logging.info(f">>> 随机延迟执行 {random_delay}秒") + time.sleep(random_delay) + except (ValueError, TypeError): + logging.warning(f">>> 延迟执行设置无效: {delay}") + os.system(f"{PYTHON_PATH} {args}") @@ -708,6 +722,9 @@ def reload_tasks(): logging.info(">>> 重载调度器") logging.info(f"调度状态: {scheduler_state_map[scheduler.state]}") logging.info(f"定时规则: {crontab}") + # 记录延迟执行设置 + if delay := config_data.get("crontab_delay"): + logging.info(f"延迟执行: 0-{delay}秒") logging.info(f"现有任务: {scheduler.get_jobs()}") return True else: @@ -740,6 +757,10 @@ def init(): # 默认定时规则 if not config_data.get("crontab"): config_data["crontab"] = "0 8,18,20 * * *" + + # 默认延迟执行设置 + if "crontab_delay" not in config_data: + config_data["crontab_delay"] = 0 # 初始化插件配置 _, plugins_config_default, task_plugins_config_default = Config.load_plugins() diff --git a/app/static/css/main.css b/app/static/css/main.css index da24ce9..685390c 100644 --- a/app/static/css/main.css +++ b/app/static/css/main.css @@ -3724,3 +3724,43 @@ input::-moz-list-button { background-color: #f7f7fa; /* 表头悬停背景色 */ cursor: pointer; } + +/* 移除number类型输入框的上下箭头 */ +input.no-spinner::-webkit-outer-spin-button, +input.no-spinner::-webkit-inner-spin-button { + -webkit-appearance: none; + margin: 0; +} + +/* Firefox也需要特别处理 */ +input.no-spinner { + -moz-appearance: textfield; +} + +/* 秒字框正方形样式 */ +.square-append { + width: 32px; + height: 32px; + display: flex; + align-items: center; + justify-content: center; + padding: 0 !important; +} + +/* 确保Crontab和延迟执行框在移动端也保持一行 */ +@media (max-width: 767.98px) { + .row.mb-2 .col-sm-6 { + flex: 0 0 50%; + max-width: 50%; + } + + .row.mb-2 .col-sm-6.pr-1 { + padding-right: 4px !important; + padding-left: 15px !important; + } + + .row.mb-2 .col-sm-6.pl-1 { + padding-left: 4px !important; + padding-right: 15px !important; + } +} diff --git a/app/templates/index.html b/app/templates/index.html index 280f0d9..dd1845b 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -273,11 +273,26 @@ -