mirror of
https://github.com/stablyai/orca.git
synced 2026-10-07 08:02:21 +00:00
* oom(01): A1-shared-readers — reintroduce #10179 subset Files: 18 applied, 0 deleted (from6eb70d8370) Co-authored-by: Orca <help@stably.ai> * oom(02): A2-shared-image-media — reintroduce #10179 subset Files: 7 applied, 0 deleted (from6eb70d8370) Co-authored-by: Orca <help@stably.ai> * oom(03): A3-shared-fs-listing — reintroduce #10179 subset Files: 21 applied, 0 deleted (from6eb70d8370) Co-authored-by: Orca <help@stably.ai> * oom(04): A4-shared-remote-relay — reintroduce #10179 subset Files: 8 applied, 0 deleted (from6eb70d8370) Co-authored-by: Orca <help@stably.ai> * oom(05): A5-shared-misc — reintroduce #10179 subset Files: 28 applied, 0 deleted (from6eb70d8370) Co-authored-by: Orca <help@stably.ai> * oom(06): B-shared-wiring — reintroduce #10179 subset Files: 81 applied, 0 deleted (from6eb70d8370) Co-authored-by: Orca <help@stably.ai> --------- Co-authored-by: Orca <help@stably.ai>
39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
import { opendirSync, statSync, unlinkSync } from 'node:fs'
|
|
import { join } from 'node:path'
|
|
|
|
export const AGENT_HOOK_ENDPOINT_SWEEP_MAX_ENTRIES = 1024
|
|
const AGENT_HOOK_ENDPOINT_STALE_MS = 5 * 60 * 1000
|
|
|
|
export function sweepStaleAgentHookEndpointTemps(endpointDir: string, now = Date.now()): void {
|
|
let directory: ReturnType<typeof opendirSync> | undefined
|
|
try {
|
|
directory = opendirSync(endpointDir, { bufferSize: 32 })
|
|
const cutoff = now - AGENT_HOOK_ENDPOINT_STALE_MS
|
|
for (let scanned = 0; scanned < AGENT_HOOK_ENDPOINT_SWEEP_MAX_ENTRIES; scanned += 1) {
|
|
const entry = directory.readSync()
|
|
if (entry === null) {
|
|
break
|
|
}
|
|
if (!entry.name.startsWith('.endpoint-') || !entry.name.endsWith('.tmp')) {
|
|
continue
|
|
}
|
|
const entryPath = join(endpointDir, entry.name)
|
|
try {
|
|
if (statSync(entryPath).mtimeMs < cutoff) {
|
|
unlinkSync(entryPath)
|
|
}
|
|
} catch {
|
|
// best-effort sweep
|
|
}
|
|
}
|
|
} catch {
|
|
// Endpoint publication must still proceed on exotic filesystems.
|
|
} finally {
|
|
try {
|
|
directory?.closeSync()
|
|
} catch {
|
|
// already closed
|
|
}
|
|
}
|
|
}
|