This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
import { WORKER_HEARTBEAT_TTL_SECONDS } from "@/lib/constants/rpa";
import { listWorkerHeartbeats } from "@/workers/rpa/worker-state";
/** 是否存在近期有心跳的 RPA Worker(用于地址候选是否走 BullMQ) */
export async function isAnyRpaWorkerHealthy(
maxAgeMs = WORKER_HEARTBEAT_TTL_SECONDS * 1_000,
): Promise<boolean> {
try {
const workers = await listWorkerHeartbeats();
const now = Date.now();
return workers.some(
(worker) =>
worker.lastSeenMs !== null && now - worker.lastSeenMs <= maxAgeMs,
);
} catch {
return false;
}