MCPcopy
hub / github.com/vectorize-io/hindsight / start

Method start

hindsight-api-slim/hindsight_api/pg0.py:65–93  ·  view source on GitHub ↗

Start the PostgreSQL server with retry logic.

(self, max_retries: int = 5, retry_delay: float = 4.0)

Source from the content-addressed store, hash-verified

63 return self._pg0
64
65 async def start(self, max_retries: int = 5, retry_delay: float = 4.0) -> str:
66 """Start the PostgreSQL server with retry logic."""
67 port_info = f"port={self.port}" if self.port else "port=auto"
68 logger.info(f"Starting embedded PostgreSQL (name={self.name}, {port_info})...")
69
70 pg0 = self._get_pg0()
71 last_error = None
72
73 for attempt in range(1, max_retries + 1):
74 try:
75 loop = asyncio.get_event_loop()
76 info = await loop.run_in_executor(None, pg0.start)
77 # Get URI from pg0 (includes auto-assigned port)
78 uri = info.uri
79 logger.info(f"PostgreSQL started: {uri}")
80 return uri
81 except Exception as e:
82 last_error = str(e)
83 if attempt < max_retries:
84 delay = retry_delay * (2 ** (attempt - 1))
85 logger.debug(f"pg0 start attempt {attempt}/{max_retries} failed: {last_error}")
86 logger.debug(f"Retrying in {delay:.1f}s...")
87 await asyncio.sleep(delay)
88 else:
89 logger.debug(f"pg0 start attempt {attempt}/{max_retries} failed: {last_error}")
90
91 raise RuntimeError(
92 f"Failed to start embedded PostgreSQL after {max_retries} attempts. Last error: {last_error}"
93 )
94
95 async def stop(self) -> None:
96 """Stop the PostgreSQL server."""

Callers 1

ensure_runningMethod · 0.95

Calls 3

_get_pg0Method · 0.95
infoMethod · 0.65
debugMethod · 0.65

Tested by

no test coverage detected