mirror of
https://github.com/stablyai/orca.git
synced 2026-09-29 16:02:50 +00:00
Copies the private repository's relay side: the IAM-only fence broker, the operations console and incident monitor, the relay Terraform root with its backend configuration and tfvars, and the deploy/capacity/admission/rehome/ monitoring scripts the workflows call, with their contract tests, contracts, and fixtures. The foundation and apps Terraform roots and the API and auth services stay private. Four surfaces that spanned both trees are narrowed to the relay side rather than left with a dangling read: the infra runner and the root-partition and workload-identity-condition renderers now declare only the relay root, and the Cloud SQL rollout census drops the six app workflows that are not here.
38 lines
1.4 KiB
JavaScript
38 lines
1.4 KiB
JavaScript
import { access, mkdir, open } from 'node:fs/promises'
|
|
import { join } from 'node:path'
|
|
import { setTimeout as delayDefault } from 'node:timers/promises'
|
|
|
|
export async function waitForRelayLoadPhaseBarrier(config, overrides = {}) {
|
|
const delay = overrides.delay ?? delayDefault
|
|
const now = overrides.now ?? Date.now
|
|
const timeoutMs = overrides.timeoutMs ?? config.timeoutMs
|
|
if (
|
|
typeof config.directory !== 'string' || config.directory.length === 0 ||
|
|
!Number.isSafeInteger(config.shardCount) || config.shardCount < 2 ||
|
|
!Number.isSafeInteger(config.shardIndex) || config.shardIndex < 0 ||
|
|
config.shardIndex >= config.shardCount ||
|
|
!Number.isSafeInteger(timeoutMs) || timeoutMs < 1
|
|
) throw new Error('invalid Relay load phase barrier')
|
|
|
|
await mkdir(config.directory, { recursive: true })
|
|
const marker = join(config.directory, `${config.shardIndex}.ready`)
|
|
const handle = await open(marker, 'wx')
|
|
await handle.close()
|
|
const deadline = now() + timeoutMs
|
|
for (;;) {
|
|
const ready = await Promise.all(
|
|
Array.from({ length: config.shardCount }, async (_, index) => {
|
|
try {
|
|
await access(join(config.directory, `${index}.ready`))
|
|
return true
|
|
} catch {
|
|
return false
|
|
}
|
|
})
|
|
)
|
|
if (ready.every(Boolean)) return
|
|
if (now() >= deadline) throw new Error('Relay load phase barrier timed out')
|
|
await delay(100)
|
|
}
|
|
}
|