Files
orca/cloud/apps/push/src/push-readiness.ts
Jinwoo Hong eb2f2d52ae feat(cloud): native push gateway and dedicated infrastructure (1/3) (#19912)
* 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
2026-09-10 17:59:46 -04:00

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
}
}