ReMe/reme/steps/index/wait_for_paths.py
jinliyl 54fa3381d7
Some checks failed
CI and Release / Docker / Build and test / amd64 (push) Has been cancelled
CI and Release / Docker / Build and test / arm64 (push) Has been cancelled
Security / CodeQL / Analyze python (push) Has been cancelled
CI / Python quality / Pre-commit (push) Has been cancelled
CI / Python tests / Unit Tests - py3.12 (push) Has been cancelled
CI / Python tests / Unit Tests - py3.13 (push) Has been cancelled
CI / Python tests / Unit Tests - py3.14 (push) Has been cancelled
CI / Python packages / Build and verify distributions (push) Has been cancelled
CI / Python quality / GitHub Actions (push) Has been cancelled
CI / Python tests / Hermes embedded - ubuntu-latest (push) Has been cancelled
CI / Python tests / Hermes embedded - windows-latest (push) Has been cancelled
CI / Python tests / Unit Tests - py3.11 (push) Has been cancelled
CI / ReMe Studio / Studio checks (push) Has been cancelled
Deploy / Documentation / Build documentation (push) Has been cancelled
CI / Windows / CLI smoke - py3.11 (push) Has been cancelled
Security / CodeQL / Analyze javascript-typescript (push) Has been cancelled
CI and Release / Docker / Publish multi-platform tags (push) Has been cancelled
Deploy / Documentation / deploy (push) Has been cancelled
refactor(core): reorganize the ReMe runtime and shared helpers (#769)
* refactor(core): reorganize the ReMe runtime and shared helpers

* test(status): import the base component from its canonical module

* test: remove redundant unit checks

* refactor(core): use canonical runtime imports and shared CLI discovery

Restore evolve behavior to the base branch and update its imports. Use Application as the runtime entry point and encode SSE in the HTTP service.

* fix(cli): honor caller config when service replay is incomplete

Use partial startup overrides for port probes and resolve named configs before requesting the service process working directory.
2026-11-20 22:06:46 +08:00

56 lines
2.2 KiB
Python

"""Wait for required workspace files before continuing a job."""
import asyncio
import time
from pathlib import Path
from ..base_step import BaseStep
from ...core.registry import R
@R.register("wait_for_paths_step")
class WaitForPathsStep(BaseStep):
"""Block until configured workspace-relative paths exist."""
def _targets(self) -> list[str]:
"""Collect workspace-relative targets from ``paths`` + ``config_keys``."""
rels: list[str] = list(self.kwargs.get("paths") or [])
for key in self.kwargs.get("config_keys") or []:
value = self.config_value(key)
if value:
rels.append(str(value))
return rels
async def execute(self):
assert self.context is not None
poll_seconds = float(self.kwargs.get("poll_seconds", 5.0))
log_every_seconds = float(self.kwargs.get("log_every_seconds", 60.0))
root = self.workspace_path.resolve()
targets: list[tuple[str, Path]] = []
for rel in self._targets():
target = (self.workspace_path / rel).resolve()
if target == root or root not in target.parents:
raise ValueError(f"wait_for_paths_step refuses out-of-workspace path: {rel!r}")
targets.append((rel, target))
if not targets:
return self.context.response
start = time.monotonic()
last_log_at = 0.0
while True:
missing = [rel for rel, target in targets if not target.exists()]
if not missing:
waited_seconds = time.monotonic() - start
self.context.response.metadata["waited_for_paths"] = [rel for rel, _ in targets]
self.context.response.metadata["waited_seconds"] = waited_seconds
self.logger.info(f"[{self.name}] required paths are ready after {waited_seconds:.1f}s")
return self.context.response
now = time.monotonic()
if now - last_log_at >= log_every_seconds:
waited_seconds = now - start
self.logger.info(f"[{self.name}] waiting for {missing} ({waited_seconds:.1f}s elapsed)")
last_log_at = now
await asyncio.sleep(poll_seconds)