k
This commit is contained in:
@@ -11,6 +11,13 @@ def repl_queue_dir(root: Path) -> Path:
|
||||
return Path(root) / "Log" / "repl_queue"
|
||||
|
||||
|
||||
def _legacy_repl_queue_glob(root: Path) -> list[Path]:
|
||||
log_dir = Path(root) / "Log"
|
||||
if not log_dir.exists():
|
||||
return []
|
||||
return list(log_dir.glob("medeia-repl-queue-*.json"))
|
||||
|
||||
|
||||
def enqueue_repl_command(
|
||||
root: Path,
|
||||
command: str,
|
||||
@@ -41,11 +48,24 @@ def enqueue_repl_command(
|
||||
|
||||
def pop_repl_commands(root: Path, *, limit: int = 8) -> List[Dict[str, Any]]:
|
||||
queue_dir = repl_queue_dir(root)
|
||||
if not queue_dir.exists():
|
||||
legacy_entries = _legacy_repl_queue_glob(root)
|
||||
if not queue_dir.exists() and not legacy_entries:
|
||||
return []
|
||||
|
||||
items: List[Dict[str, Any]] = []
|
||||
for entry in sorted(queue_dir.glob("*.json"))[: max(1, int(limit or 1))]:
|
||||
entries: List[Path] = []
|
||||
if queue_dir.exists():
|
||||
entries.extend(queue_dir.glob("*.json"))
|
||||
entries.extend(legacy_entries)
|
||||
|
||||
def _sort_key(path: Path) -> tuple[float, str]:
|
||||
try:
|
||||
ts = float(path.stat().st_mtime)
|
||||
except Exception:
|
||||
ts = 0.0
|
||||
return (ts, path.name)
|
||||
|
||||
for entry in sorted(entries, key=_sort_key)[: max(1, int(limit or 1))]:
|
||||
try:
|
||||
payload = json.loads(entry.read_text(encoding="utf-8"))
|
||||
except Exception:
|
||||
|
||||
Reference in New Issue
Block a user