mirror of
https://github.com/stablyai/orca.git
synced 2026-09-22 16:02:32 +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
22 lines
599 B
TypeScript
22 lines
599 B
TypeScript
// Bound unauthenticated database lookups independently of Cloud Run HTTP concurrency.
|
|
export class PushAuthAdmission {
|
|
private active = 0
|
|
private readonly waiting: (() => void)[] = []
|
|
|
|
async run<T>(operation: () => Promise<T>): Promise<T | null> {
|
|
if (this.active >= 4) {
|
|
if (this.waiting.length >= 32) return null
|
|
await new Promise<void>((resolve) => this.waiting.push(resolve))
|
|
} else {
|
|
this.active++
|
|
}
|
|
try {
|
|
return await operation()
|
|
} finally {
|
|
const next = this.waiting.shift()
|
|
if (next) next()
|
|
else this.active--
|
|
}
|
|
}
|
|
}
|