* Wait for Electric server to be ready
(url: string)
| 44 | * Wait for Electric server to be ready |
| 45 | */ |
| 46 | async function waitForElectric(url: string): Promise<void> { |
| 47 | return new Promise<void>((resolve, reject) => { |
| 48 | const timeout = setTimeout(() => { |
| 49 | reject(new Error(`Timed out waiting for Electric to be active at ${url}`)) |
| 50 | }, 10000) |
| 51 | |
| 52 | const check = async (): Promise<void> => { |
| 53 | try { |
| 54 | const res = await fetch(`${url}/v1/health`) |
| 55 | if (res.ok) { |
| 56 | const data = (await res.json()) as { status: string } |
| 57 | if (data.status === 'active') { |
| 58 | clearTimeout(timeout) |
| 59 | return resolve() |
| 60 | } |
| 61 | } |
| 62 | setTimeout(() => void check(), 100) |
| 63 | } catch { |
| 64 | setTimeout(() => void check(), 100) |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | void check() |
| 69 | }) |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Wait for Postgres to be ready |