Commit ed8738f2 authored by 郭阔's avatar 郭阔

fix(panel): running-harvest detection covers manually triggered runs

active_harvests() only read launchd/systemd service state, so runs started
via the panel button or a terminal (not launchd) were invisible on the
homepage. Union with runlock-based detection: each port-<port>.<pid>.lock
created by harvest.sh itself, PID liveness-checked, source name recovered
from the PID's command line — launcher-independent.
parent 3eadf69a
......@@ -7,6 +7,7 @@ bash 侧的同一实现,保证脚本与面板永远行为一致;读取类操作
import json
import os
import re
import subprocess
import sys
from datetime import datetime, timedelta
......@@ -371,7 +372,37 @@ def service_state(name):
def active_harvests():
return [n for n, _ in list_schedules().items() if service_state(n) == "running"]
"""正在运行的采集源名列表(跨启动方式)。
launchd/systemd 服务态只能看到定时触发的任务;手动触发(面板按钮、
终端)不经过服务管理器。runlocks(port-<port>.<pid>.lock)由 harvest.sh
自身创建,对 PID 反查命令行可得源名 —— 两者取并集。
"""
active = [n for n, _ in list_schedules().items() if service_state(n) == "running"]
lockdir = Path(default_work_dir()) / "runlocks"
if not lockdir.is_dir():
return active
for f in sorted(lockdir.glob("port-*.lock")):
stem = f.name[:-5] # port-<port>.<pid>
try:
pid = int(stem.rsplit(".", 1)[1])
except (ValueError, IndexError):
continue
try:
os.kill(pid, 0) # 进程存活检查
except OSError:
continue
try:
cmd = subprocess.run(
["ps", "-p", str(pid), "-o", "command="],
capture_output=True, text=True, timeout=5,
).stdout
except Exception: # noqa: BLE001
continue
m = re.search(r"harvest\.sh\s+([A-Za-z0-9_-]+)", cmd)
if m and m.group(1) not in active:
active.append(m.group(1))
return active
def schedule_enable(name):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment