workflow_client.py 1001 B

123456789101112131415161718192021222324252627282930
  1. import httpx
  2. from core_domain import WorkflowVersionContract
  3. class WorkflowServiceClientError(Exception):
  4. pass
  5. class WorkflowServiceClient:
  6. def __init__(self, base_url: str, timeout_seconds: float = 10.0) -> None:
  7. self.base_url = base_url.rstrip("/")
  8. self.timeout_seconds = timeout_seconds
  9. def get_workflow_version(
  10. self,
  11. *,
  12. tenant_id: str,
  13. workflow_version_id: str,
  14. ) -> WorkflowVersionContract:
  15. try:
  16. with httpx.Client(timeout=self.timeout_seconds) as client:
  17. response = client.get(
  18. f"{self.base_url}/workflows/versions/{workflow_version_id}",
  19. params={"tenant_id": tenant_id},
  20. )
  21. response.raise_for_status()
  22. return WorkflowVersionContract.model_validate(response.json())
  23. except httpx.HTTPError as exc:
  24. raise WorkflowServiceClientError(f"workflow-service request failed: {exc}") from exc