diff --git a/.travis.yml b/.travis.yml index 8b252f2a..8f0f5549 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ dist: focal language: node_js node_js: - - 19.6.0 + - 19.7.0 notifications: diff --git a/boot.mjs b/boot.mjs index 5d5c7e38..64130510 100644 --- a/boot.mjs +++ b/boot.mjs @@ -6,23 +6,25 @@ import { exec } from 'child_process'; import pjson from './package.json' assert { type: 'json' }; // Displays version of Node JS being used at runtime and others attributes. - - console.log(``); console.log(``); -console.log(` ██████ ███████ ███ ██ ███████ ██████ █████ ██ ██████ ██████ ████████ ███████ ® `); -console.log(`██ ██ ████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ `); -console.log(`██ ███ █████ ██ ██ ██ █████ ██████ ███████ ██ ██████ ██ ██ ██ ███████ `); -console.log(`██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ `); -console.log(` ██████ ███████ ██ ████ ███████ ██ ██ ██ ██ ██████ ██████ ██████ ██ ███████ 3.0`); -console.log(`botserver@${pjson.version}, botlib@${pjson.dependencies.botlib}, botbuilder@${pjson.dependencies.botbuilder}, node@${process.version}, ${process.platform}(${process.arch}).`); +console.log(` █████ █████ ██ █ █████ █████ ████ ██ ████ █████ █████ ███ ® `); +console.log(`██ █ ███ █ █ ██ ██ ██ ██ ██ ██ █ ██ ██ █ █ `); +console.log(`██ ███ ████ █ ██ █ ████ █████ ██████ ██ ████ █ █ █ ██ `); +console.log(`██ ██ █ █ ██ █ █ ██ ██ ██ ██ ██ ██ █ ██ ██ █ █ `); +console.log(` █████ █████ █ ███ █████ ██ ██ ██ ██ ██████ ████ █████ █ ███ 3.0`); +console.log(` botserver@${pjson.version}, botlib@${pjson.dependencies.botlib}, botbuilder@${pjson.dependencies.botbuilder}, node@${process.version.replace('v', '')}, ${process.platform} ${process.arch}`); + var now = () => { return new Date().toISOString().replace(/T/, ' ').replace(/\..+/, '') + ' UTC'; }; var __dirname = process.env.PWD || process.cwd(); try { var run = () => { - import('./dist/src/app.js').then((gb)=> gb.GBServer.run()); + import('./dist/src/app.js').then((gb)=> { + console.log(``); + gb.GBServer.run() + }); }; var processDist = () => { if (!Fs.existsSync('dist')) { diff --git a/package.json b/package.json index fad430d2..c2142bce 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "Dário Vieira " ], "engines": { - "node": "=19.6.0" + "node": "=19.7.0" }, "license": "AGPL-3.0", "preferGlobal": true, diff --git a/packages/core.gbapp/services/GBDeployer.ts b/packages/core.gbapp/services/GBDeployer.ts index 5209c31c..aa0a882e 100644 --- a/packages/core.gbapp/services/GBDeployer.ts +++ b/packages/core.gbapp/services/GBDeployer.ts @@ -57,6 +57,7 @@ import { GBConfigService } from './GBConfigService.js'; import { GBImporter } from './GBImporterService.js'; import { TeamsService } from '../../teams.gblib/services/TeamsService.js'; import MicrosoftGraph from '@microsoft/microsoft-graph-client'; +import { GBLogEx } from './GBLogEx.js'; /** * Deployer service for bots, themes, ai and more. @@ -655,8 +656,8 @@ export class GBDeployer implements IGBDeployer { break; default: - throw GBError.create(`Unhandled package type: ${packageType}.`); -} + throw GBError.create(`Unhandled package type: ${packageType}.`); + } } /** @@ -712,38 +713,45 @@ export class GBDeployer implements IGBDeployer { */ public async rebuildIndex(instance: IGBInstance, searchSchema: any) { // Prepares search. - - - const search = new AzureSearch( - instance.searchKey, - instance.searchHost, - instance.searchIndex, - instance.searchIndexer - ); - const connectionString = GBDeployer.getConnectionStringFromInstance(instance); - const dsName = 'gb'; + let release; try { - await search.createDataSource(dsName, dsName, 'GuaribasQuestion', 'azuresql', connectionString); - } catch (err) { - GBLog.error(err); + GBLogEx.info(instance.instanceId, `Acquiring rebuildIndex mutex...`); + release = await GBServer.globals.indexSemaphore.acquire(); - } + const search = new AzureSearch( + instance.searchKey, + instance.searchHost, + instance.searchIndex, + instance.searchIndexer + ); + const connectionString = GBDeployer.getConnectionStringFromInstance(instance); + const dsName = 'gb'; + try { + await search.createDataSource(dsName, dsName, 'GuaribasQuestion', 'azuresql', connectionString); + } catch (err) { + GBLog.error(err); + } - // Removes the index. + // Removes the index. - try { - await search.createIndex(searchSchema, dsName); - } catch (err) { - // If it is a 404 there is nothing to delete as it is the first creation. + try { + await search.createIndex(searchSchema, dsName); + } catch (err) { + // If it is a 404 there is nothing to delete as it is the first creation. - if (err.code !== 404 && err.code !== 'OperationNotAllowed') { + if (err.code !== 404 && err.code !== 'OperationNotAllowed') { + } + } + GBLogEx.info(instance.instanceId, `Acquire rebuildIndex done.`); + await search.rebuildIndex(instance.searchIndexer); + release(); + GBLogEx.info(instance.instanceId, `Released rebuildIndex mutex.`); + } catch { + if (release) { + release(); } } - - - await search.rebuildIndex(instance.searchIndexer); - } /** diff --git a/src/RootData.ts b/src/RootData.ts index 68794993..abecfa3b 100644 --- a/src/RootData.ts +++ b/src/RootData.ts @@ -59,4 +59,5 @@ export class RootData { public debugConversationId: any; // Used to self-message during debug. public debuggers: any[]; // Client of attached Debugger instances by botId. public chatGPT: any; // ChatGPT API handle (shared Browser). + indexSemaphore: any; } diff --git a/src/app.ts b/src/app.ts index ad139aa5..89b716fb 100644 --- a/src/app.ts +++ b/src/app.ts @@ -56,6 +56,7 @@ import child_process from 'child_process'; import * as winston from 'winston-logs-display'; import { RootData } from './RootData.js'; import { GBSSR } from '../packages/core.gbapp/services/GBSSR.js'; +import { Mutex } from 'async-mutex'; /** * General Bots open-core entry point. @@ -95,6 +96,8 @@ export class GBServer { GBServer.globals.wwwroot = null; GBServer.globals.entryPointDialog = null; GBServer.globals.debuggers = []; + GBServer.globals.indexSemaphore = new Mutex(); + server.use(bodyParser.json()); server.use(bodyParser.urlencoded({ extended: true }));