mirror of
https://github.com/Cp0204/quark-auto-save.git
synced 2026-01-16 17:30:43 +08:00
Compare commits
3 Commits
20b12ea23a
...
bd9222c875
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bd9222c875 | ||
|
|
956105c16e | ||
|
|
78581b15a7 |
31
app/run.py
31
app/run.py
@ -23,6 +23,7 @@ import subprocess
|
||||
import requests
|
||||
import hashlib
|
||||
import logging
|
||||
import traceback
|
||||
import base64
|
||||
import sys
|
||||
import os
|
||||
@ -470,7 +471,35 @@ def add_task():
|
||||
# 定时任务执行的函数
|
||||
def run_python(args):
|
||||
logging.info(f">>> 定时运行任务")
|
||||
os.system(f"{PYTHON_PATH} {args}")
|
||||
try:
|
||||
# 使用 subprocess 替代 os.system,并设置超时时间(默认30分钟)
|
||||
timeout = int(os.environ.get("TASK_TIMEOUT", "1800")) # 秒
|
||||
result = subprocess.run(
|
||||
f"{PYTHON_PATH} {args}",
|
||||
shell=True,
|
||||
timeout=timeout,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
encoding="utf-8",
|
||||
errors="replace"
|
||||
)
|
||||
# 输出执行日志
|
||||
if result.stdout:
|
||||
for line in result.stdout.strip().split('\n'):
|
||||
if line.strip():
|
||||
logging.info(line)
|
||||
|
||||
if result.returncode == 0:
|
||||
logging.info(f">>> 任务执行成功")
|
||||
else:
|
||||
logging.error(f">>> 任务执行失败,返回码: {result.returncode}")
|
||||
if result.stderr:
|
||||
logging.error(f"错误信息: {result.stderr[:500]}")
|
||||
except subprocess.TimeoutExpired:
|
||||
logging.error(f">>> 任务执行超时(超过 {timeout} 秒),已强制终止")
|
||||
except Exception as e:
|
||||
logging.error(f">>> 任务执行异常: {str(e)}")
|
||||
logging.error(traceback.format_exc())
|
||||
|
||||
|
||||
# 重新加载任务
|
||||
|
||||
@ -164,7 +164,7 @@ class MagicRename:
|
||||
"{YEAR}": [r"(?<!\d)(18|19|20)\d{2}(?!\d)"],
|
||||
"{S}": [r"(?<=[Ss])\d{1,2}(?=[EeXx])", r"(?<=[Ss])\d{1,2}"],
|
||||
"{SXX}": [r"[Ss]\d{1,2}(?=[EeXx])", r"[Ss]\d{1,2}"],
|
||||
"{E}": [
|
||||
"{E+}": [
|
||||
r"(?<=[Ss]\d\d[Ee])\d{1,3}",
|
||||
r"(?<=[Ee])\d{1,3}",
|
||||
r"(?<=[Ee][Pp])\d{1,3}",
|
||||
@ -224,7 +224,7 @@ class MagicRename:
|
||||
return file_name
|
||||
# 预处理替换变量
|
||||
for key, p_list in self.magic_variable.items():
|
||||
if key in replace:
|
||||
if match_key := re.search(key, replace):
|
||||
# 正则类替换变量
|
||||
if p_list and isinstance(p_list, list):
|
||||
for p in p_list:
|
||||
@ -240,7 +240,10 @@ class MagicRename:
|
||||
value = (
|
||||
str(datetime.now().year)[: (8 - len(value))] + value
|
||||
)
|
||||
replace = replace.replace(key, value)
|
||||
# 集数零填充处理
|
||||
elif key == "{E+}":
|
||||
value = value.lstrip("0").zfill(match_key.group().count("E"))
|
||||
replace = re.sub(key, value, replace)
|
||||
break
|
||||
# 非正则类替换变量
|
||||
if key == "{TASKNAME}":
|
||||
@ -251,7 +254,7 @@ class MagicRename:
|
||||
continue
|
||||
else:
|
||||
# 清理未匹配的 magic_variable key
|
||||
replace = replace.replace(key, "")
|
||||
replace = re.sub(key, "", replace)
|
||||
if pattern and replace:
|
||||
file_name = re.sub(pattern, replace, file_name)
|
||||
else:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user