MCPcopy
hub / github.com/CodebuffAI/codebuff / waitForPostgres

Function waitForPostgres

packages/internal/src/db/e2e-setup.ts:53–80  ·  view source on GitHub ↗
(
  url: string,
  maxAttempts = 30,
  delayMs = 1000
)

Source from the content-addressed store, hash-verified

51}
52
53const waitForPostgres = async (
54 url: string,
55 maxAttempts = 30,
56 delayMs = 1000
57): Promise<void> => {
58 for (let attempt = 1; attempt <= maxAttempts; attempt++) {
59 let testClient: ReturnType<typeof postgres> | null = null
60 try {
61 testClient = postgres(url, { max: 1, connect_timeout: 5 })
62 await testClient`SELECT 1`
63 return
64 } catch (error) {
65 if (attempt === maxAttempts) {
66 throw new Error(
67 `Failed to connect to Postgres after ${maxAttempts} attempts: ${error}`
68 )
69 }
70 console.log(
71 `Waiting for Postgres to be ready... (attempt ${attempt}/${maxAttempts})`
72 )
73 await new Promise((resolve) => setTimeout(resolve, delayMs))
74 } finally {
75 if (testClient) {
76 await testClient.end()
77 }
78 }
79 }
80}
81
82run('docker', ['compose', '-f', composeFile, 'up', '-d', '--wait'])
83

Callers 1

e2e-setup.tsFile · 0.85

Calls 1

setTimeoutFunction · 0.85

Tested by

no test coverage detected