openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
52 lines (51 loc) • 1.84 kB
JavaScript
import { c as publishLaneConfiguration, f as getLaneGroup, p as getQueueState } from "./command-queue-BenRlAaO.mjs";
//#region src/process/background-work.ts
const BACKGROUND_WORK_GROUP = "background-work";
const BACKGROUND_WORK_MAX_CONCURRENT = 3;
/** Lazily register Workshop's serial lane, including after queue-state resets. */
function getSkillWorkshopReviewLane() {
const e = `${"background"}:core:skill-workshop`;
if (getLaneGroup(e)) {
if ((getQueueState().lanes.get(e)?.maxConcurrent ?? 1) !== 1) throw new Error("Background owner core:skill-workshop is already registered with different concurrency");
} else {
const t = getQueueState().laneGroups.get(BACKGROUND_WORK_GROUP);
publishLaneConfiguration({
lanes: { [e]: 1 },
groups: { [BACKGROUND_WORK_GROUP]: {
budget: BACKGROUND_WORK_MAX_CONCURRENT,
members: [...t?.members ?? [], e]
} }
});
}
return e;
}
function isBackgroundWorkLane(e) {
return getLaneGroup(e)?.group === BACKGROUND_WORK_GROUP;
}
function getBackgroundWorkSnapshot() {
const { lanes: e, laneGroups: t } = getQueueState();
const n = t.get(BACKGROUND_WORK_GROUP);
const r = {
lane: "background",
activeCount: 0,
queuedCount: 0,
maxConcurrent: BACKGROUND_WORK_MAX_CONCURRENT,
draining: false,
generation: 0,
blockedBy: null
};
for (const t of n?.members ?? []) {
const n = e.get(t);
if (!n) continue;
const i = n.activeTasks.size;
r.activeCount += i;
r.queuedCount += n.queue.length;
r.draining ||= n.draining;
r.generation = Math.max(r.generation, n.generation);
if (n.queue.length > 0 && i >= n.maxConcurrent) r.blockedBy = "lane";
}
if (r.activeCount >= BACKGROUND_WORK_MAX_CONCURRENT) r.blockedBy = "group-budget";
return r;
}
//#endregion
export { getSkillWorkshopReviewLane as n, isBackgroundWorkLane as r, getBackgroundWorkSnapshot as t };