mirror of
https://github.com/stablyai/orca.git
synced 2026-09-28 08:02:43 +00:00
* refactor(cloud): share PostgreSQL schema startup between services * feat(cloud): add durable native push notification gateway * infra(push): define dedicated gateway resources and operational checks * fix(push): bound cross-host admission and simplify gateway configuration * fix(push): validate deploy configuration and preserve topic-error registrations
40 lines
981 B
TypeScript
40 lines
981 B
TypeScript
import type { PushDatabase } from './push-database.js'
|
|
|
|
export type PushReadinessOptions = {
|
|
cacheMs?: number
|
|
now?: () => number
|
|
}
|
|
|
|
// The gateway holds no JWKS dependency, so readiness is exactly "can we reach
|
|
// the database": /health stays unconditional for the container probe.
|
|
export function createPushReadiness(
|
|
database: PushDatabase,
|
|
options: PushReadinessOptions = {}
|
|
): () => Promise<boolean> {
|
|
const cacheMs = options.cacheMs ?? 10_000
|
|
const now = options.now ?? Date.now
|
|
let cachedAt = Number.NEGATIVE_INFINITY
|
|
let cached = false
|
|
|
|
let pending: Promise<boolean> | null = null
|
|
|
|
async function check(): Promise<boolean> {
|
|
try {
|
|
await database.query('SELECT 1 AS ready')
|
|
cached = true
|
|
} catch {
|
|
cached = false
|
|
}
|
|
cachedAt = now()
|
|
return cached
|
|
}
|
|
|
|
return async () => {
|
|
if (now() - cachedAt < cacheMs) return cached
|
|
pending ??= check().finally(() => {
|
|
pending = null
|
|
})
|
|
return pending
|
|
}
|
|
}
|