new(all): Paralel bot loading.

This commit is contained in:
rodrigorodriguez 2022-10-10 00:00:30 -03:00
parent 73f20825e7
commit 16801fcb6c
2 changed files with 15 additions and 12 deletions

View file

@ -172,23 +172,26 @@ export class GBMinService {
// Calls mountBot event to all bots. // Calls mountBot event to all bots.
const bar1 = new cliProgress.SingleBar({ const bar1 = new cliProgress.SingleBar({
format: '[{bar}] Loading {botId} ({value}/{total})...', barsize:60 format: '[{bar}] Loading {botId} ({value}/{total})...', barsize: 60
}, cliProgress.Presets.rect); }, cliProgress.Presets.rect);
let i = 0; let i = 0;
bar1.start(instances.length, i, {botId: "Boot"}); bar1.start(instances.length, i, { botId: "Boot" });
await CollectionUtil.asyncForEach(instances, async instance => { const p = (async (instance) => {
try { try {
bar1.update(i, {botId: instance.botId}); 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++; 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);
Promise.all(instances.map(instance => p(instance)));
bar1.stop(); bar1.stop();
// Loads schedules. // Loads schedules.

View file

@ -202,7 +202,7 @@ export class WhatsappDirectLine extends GBService {
client.on('authenticated', async () => { client.on('authenticated', async () => {
this.browserWSEndpoint = client.pupBrowser.wsEndpoint(); this.browserWSEndpoint = client.pupBrowser.wsEndpoint();
GBLog.verbose(`\nGBWhatsApp: QR Code authenticated for ${this.botId}.`); GBLog.verbose(`GBWhatsApp: QR Code authenticated for ${this.botId}.`);
}); });
client.on('ready', async () => { client.on('ready', async () => {
@ -212,7 +212,7 @@ export class WhatsappDirectLine extends GBService {
await (createClient.bind(this))(null); await (createClient.bind(this))(null);
}).bind(this)); }).bind(this));
GBLog.verbose(`\nGBWhatsApp: Emptying chat list for ${this.botId}...`); GBLog.verbose(`GBWhatsApp: Emptying chat list for ${this.botId}...`);
// Keeps the chat list cleaned. // Keeps the chat list cleaned.