new(all): Paralel bot loading.

This commit is contained in:
rodrigorodriguez 2022-10-10 00:58:48 -03:00
parent 24a3af5051
commit 1db979ddbf

View file

@ -120,7 +120,7 @@ export class GBMinService {
bar1; bar1;
/** /**
* Static initialization of minimal instance. * Static initialization of minimal instance.
*/ */
@ -183,7 +183,7 @@ export class GBMinService {
const throttledPromiseAll = async (promises) => { const throttledPromiseAll = async (promises) => {
const MAX_IN_PROCESS = 5; const MAX_IN_PROCESS = 5;
const results = new Array(promises.length); const results = new Array(promises.length);
async function doBlock(startIndex) { async function doBlock(startIndex) {
// Shallow-copy a block of promises to work on // Shallow-copy a block of promises to work on
const currBlock = promises.slice(startIndex, startIndex + MAX_IN_PROCESS); const currBlock = promises.slice(startIndex, startIndex + MAX_IN_PROCESS);
@ -194,27 +194,26 @@ export class GBMinService {
results[ix + startIndex] = blockResults[ix]; results[ix + startIndex] = blockResults[ix];
} }
} }
for (let iBlock = 0; iBlock < promises.length; iBlock += MAX_IN_PROCESS) { for (let iBlock = 0; iBlock < promises.length; iBlock += MAX_IN_PROCESS) {
await doBlock(iBlock); await doBlock(iBlock);
} }
return results; return results;
}; };
const p = (async (instance) => { await throttledPromiseAll(instances.map((async instance => {
try { try {
this.bar1.update(i, { botId: instance.botId }); this.bar1.update(i, { botId: instance.botId });
await this['mountBot'](instance); await this['mountBot'](instance);
GBDeployer.mountGBKBAssets(`${instance.botId}.gbkb`, GBDeployer.mountGBKBAssets(`${instance.botId}.gbkb`,
instance.botId, `${instance.botId}.gbkb`); instance.botId, `${instance.botId}.gbkb`);
i++;
} catch (error) { } catch (error) {
GBLog.error(`Error mounting bot ${instance.botId}: ${error.message}\n${error.stack}`); GBLog.error(`Error mounting bot ${instance.botId}: ${error.message}\n${error.stack}`);
} }
}).bind(this);
}).bind(this)));
await throttledPromiseAll(instances.map(instance => p(instance)));
this.bar1.stop(); this.bar1.stop();