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
29 lines
714 B
TypeScript
29 lines
714 B
TypeScript
import type { MiddlewareHandler } from 'hono'
|
|
|
|
export class PushRequestDrain {
|
|
private draining = false
|
|
private active = 0
|
|
private readonly waiters = new Set<() => void>()
|
|
|
|
readonly middleware: MiddlewareHandler = async (context, next) => {
|
|
if (this.draining) return context.json({ error: 'shutting_down' }, 503)
|
|
this.active++
|
|
try {
|
|
await next()
|
|
} finally {
|
|
this.active--
|
|
if (this.active === 0) {
|
|
for (const resolve of this.waiters) resolve()
|
|
this.waiters.clear()
|
|
}
|
|
}
|
|
}
|
|
|
|
begin(): Promise<void> {
|
|
this.draining = true
|
|
return this.active === 0
|
|
? Promise.resolve()
|
|
: new Promise((resolve) => this.waiters.add(resolve))
|
|
}
|
|
}
|