MCPcopy Index your code
hub / github.com/simstudioai/sim / selectOwnerForDispatch

Function selectOwnerForDispatch

apps/sim/lib/execution/isolated-vm.ts:565–608  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

563}
564
565function selectOwnerForDispatch(): OwnerState | null {
566 if (queuedOwnerRing.length === 0) return null
567
568 let visited = 0
569 while (queuedOwnerRing.length > 0 && visited < queuedOwnerRing.length) {
570 if (queuedOwnerCursor >= queuedOwnerRing.length) {
571 queuedOwnerCursor = 0
572 }
573 const ownerKey = queuedOwnerRing[queuedOwnerCursor]
574 if (!ownerKey) return null
575
576 const owner = ownerStates.get(ownerKey)
577 if (!owner) {
578 removeOwnerFromRing(ownerKey)
579 continue
580 }
581
582 if (owner.queueLength === 0) {
583 owner.burstRemaining = 0
584 removeOwnerFromRing(ownerKey)
585 continue
586 }
587
588 if (owner.activeExecutions >= MAX_ACTIVE_PER_OWNER) {
589 owner.burstRemaining = 0
590 queuedOwnerCursor = (queuedOwnerCursor + 1) % queuedOwnerRing.length
591 visited++
592 continue
593 }
594
595 if (owner.burstRemaining <= 0) {
596 owner.burstRemaining = owner.weight
597 }
598
599 owner.burstRemaining--
600 if (owner.burstRemaining <= 0) {
601 queuedOwnerCursor = (queuedOwnerCursor + 1) % queuedOwnerRing.length
602 }
603
604 return owner
605 }
606
607 return null
608}
609
610function scheduleDrainRetry() {
611 if (queueDrainRetryTimeout || queueSize === 0) return

Callers 1

drainQueueFunction · 0.85

Calls 2

removeOwnerFromRingFunction · 0.85
getMethod · 0.65

Tested by

no test coverage detected