dankgrinder 5.20.0 → 5.21.0
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/lib/grinder.js +29 -11
- package/package.json +1 -1
package/lib/grinder.js
CHANGED
|
@@ -2418,18 +2418,36 @@ async function start(apiKey, apiUrl) {
|
|
|
2418
2418
|
log('info', `${c.dim}Checking inventory for all ${workers.length} accounts...${c.reset}`);
|
|
2419
2419
|
let invDone = 0;
|
|
2420
2420
|
let invFailed = 0;
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2421
|
+
const parsedInvConcurrency = Number.parseInt(String(process.env.INV_STARTUP_CONCURRENCY || ''), 10);
|
|
2422
|
+
const invConcurrency = Math.max(1, Math.min(
|
|
2423
|
+
workers.length,
|
|
2424
|
+
Number.isFinite(parsedInvConcurrency) && parsedInvConcurrency > 0
|
|
2425
|
+
? parsedInvConcurrency
|
|
2426
|
+
: Math.min(10, Math.max(3, Math.ceil(workers.length / 8)))
|
|
2427
|
+
));
|
|
2428
|
+
log('info', `${c.dim}[inv-startup] parallel workers: ${invConcurrency}${c.reset}`);
|
|
2429
|
+
|
|
2430
|
+
let invCursor = 0;
|
|
2431
|
+
const runInventoryWorker = async (slot) => {
|
|
2432
|
+
while (!shutdownCalled) {
|
|
2433
|
+
const i = invCursor++;
|
|
2434
|
+
if (i >= workers.length) break;
|
|
2435
|
+
const w = workers[i];
|
|
2436
|
+
const label = w?.username || w?.account?.label || w?.account?.id || `account-${i + 1}`;
|
|
2437
|
+
log('info', `${c.dim}[inv-startup] ${i + 1}/${workers.length} ${label} ${c.dim}(runner ${slot})${c.reset}`);
|
|
2438
|
+
try {
|
|
2439
|
+
await w.checkInventory({ force: true, startupProgress: { current: i + 1, total: workers.length } });
|
|
2440
|
+
invDone++;
|
|
2441
|
+
} catch {
|
|
2442
|
+
invFailed++;
|
|
2443
|
+
}
|
|
2444
|
+
const invComplete = invDone + invFailed;
|
|
2445
|
+
log('info', `${c.dim}[inv-startup-progress] ${invComplete}/${workers.length} complete (${invDone} ok, ${invFailed} failed)${c.reset}`);
|
|
2446
|
+
await new Promise(r => setTimeout(r, 200 + Math.floor(Math.random() * 400)));
|
|
2430
2447
|
}
|
|
2431
|
-
|
|
2432
|
-
|
|
2448
|
+
};
|
|
2449
|
+
|
|
2450
|
+
await Promise.all(Array.from({ length: invConcurrency }, (_, idx) => runInventoryWorker(idx + 1)));
|
|
2433
2451
|
const invSummaryColor = invFailed > 0 ? c.yellow : c.green;
|
|
2434
2452
|
log('success', `${c.dim}Inventory phase complete: ${invSummaryColor}${invDone}/${workers.length}${c.reset}${c.dim} done${invFailed > 0 ? `, ${c.yellow}${invFailed} failed${c.reset}${c.dim}` : ''}. Starting grind loops...${c.reset}`);
|
|
2435
2453
|
|