@11agents/cli 0.1.39 → 0.1.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/commands/runtime.js +24 -5
package/package.json
CHANGED
package/src/commands/runtime.js
CHANGED
|
@@ -1653,12 +1653,31 @@ async function claimAndRunRuntimeTasks(registration, flags, deps, handlerModule,
|
|
|
1653
1653
|
}
|
|
1654
1654
|
|
|
1655
1655
|
async function drainRuntimeTasks(registration, flags, deps, handlerModule, retryState = createRetryState(), heartbeatIntervalMs = 15000, maxConcurrent = 1) {
|
|
1656
|
+
if (!handlerModule) return 0
|
|
1657
|
+
const runtimes = (registration?.runtimes || []).filter(r => r?.id)
|
|
1658
|
+
if (!runtimes.length) return 0
|
|
1659
|
+
const config = configFromFlags(flags)
|
|
1660
|
+
const machineKey = registration?.machine?.machine_key || machineOverride(flags) || ''
|
|
1661
|
+
|
|
1662
|
+
const perRuntime = Math.max(1, (deps.cpuCount ?? os.cpus().length) - 1)
|
|
1663
|
+
const effectiveConcurrent = Math.max(maxConcurrent, runtimes.length * perRuntime)
|
|
1664
|
+
|
|
1656
1665
|
let completed = 0
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1666
|
+
// Worker pool: each worker loops claiming tasks until the queue is empty,
|
|
1667
|
+
// so a fast worker immediately picks up the next task without waiting for
|
|
1668
|
+
// slow workers to finish (unlike the old batched Promise.allSettled approach).
|
|
1669
|
+
const workers = Array.from({ length: effectiveConcurrent }, (_, i) => {
|
|
1670
|
+
const runtime = runtimes[i % runtimes.length]
|
|
1671
|
+
return (async () => {
|
|
1672
|
+
while (true) {
|
|
1673
|
+
const ran = await runOneRuntimeTaskSlot(runtime, config, machineKey, registration, flags, deps, handlerModule, retryState, heartbeatIntervalMs)
|
|
1674
|
+
if (!ran) break
|
|
1675
|
+
completed++
|
|
1676
|
+
}
|
|
1677
|
+
})()
|
|
1678
|
+
})
|
|
1679
|
+
await Promise.allSettled(workers)
|
|
1680
|
+
return completed
|
|
1662
1681
|
}
|
|
1663
1682
|
|
|
1664
1683
|
export async function startRuntimeDaemon(flags = {}, deps = {}) {
|