()
| 563 | } |
| 564 | |
| 565 | function 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 | |
| 610 | function scheduleDrainRetry() { |
| 611 | if (queueDrainRetryTimeout || queueSize === 0) return |
no test coverage detected