Merge pull request #1065 from Hexastack/1063-issue---onapplicationbootstrap-remove-unused-settings
Some checks failed
Build and Push Docker API Image / build-and-push (push) Has been cancelled
Build and Push Docker Base Image / build-and-push (push) Has been cancelled
Build and Push Docker UI Image / build-and-push (push) Has been cancelled

fix(api): resolve CLI removing settings
This commit is contained in:
Med Marrouchi 2025-05-30 15:58:34 +01:00 committed by GitHub
commit ef4c61b735
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 27 additions and 1 deletions

View File

@ -9,7 +9,7 @@
import { INestApplication } from '@nestjs/common';
export class AppInstance {
private static app: INestApplication;
private static app: INestApplication | null = null;
static setApp(app: INestApplication) {
this.app = app;
@ -21,4 +21,13 @@ export class AppInstance {
}
return this.app;
}
/**
* Checks whether the application context is initialized.
* This may return `false` in environments where the app instance is not set,
* such as when running in test env or CLI mode without a full application bootstrap.
*/
static isReady(): boolean {
return this.app !== null;
}
}

View File

@ -12,6 +12,7 @@ import { Module, OnApplicationBootstrap } from '@nestjs/common';
import { MongooseModule } from '@nestjs/mongoose';
import { PassportModule } from '@nestjs/passport';
import { AppInstance } from '@/app.instance';
import { config } from '@/config';
import { UserModule } from '@/user/user.module';
@ -34,6 +35,10 @@ import { AttachmentService } from './services/attachment.service';
})
export class AttachmentModule implements OnApplicationBootstrap {
onApplicationBootstrap() {
if (!AppInstance.isReady()) {
return;
}
// Ensure the directories exists
if (!existsSync(config.parameters.uploadDir)) {
mkdirSync(config.parameters.uploadDir, { recursive: true });

View File

@ -8,6 +8,7 @@
import { Global, Module, OnApplicationBootstrap } from '@nestjs/common';
import { AppInstance } from '@/app.instance';
import { LoggerService } from '@/logger/logger.service';
import { CleanupService } from './cleanup.service';
@ -24,6 +25,11 @@ export class ExtensionModule implements OnApplicationBootstrap {
) {}
async onApplicationBootstrap() {
if (!AppInstance.isReady()) {
// bypass in test or CLI env
return;
}
try {
await this.cleanupService.pruneExtensionSettings();
} catch (error) {

View File

@ -10,6 +10,7 @@ import { Injectable, OnApplicationBootstrap } from '@nestjs/common';
import { OnEvent } from '@nestjs/event-emitter';
import Handlebars from 'handlebars';
import { AppInstance } from '@/app.instance';
import { HelperService } from '@/helper/helper.service';
import BaseNlpHelper from '@/helper/lib/base-nlp-helper';
import { HelperType, LLM, NLU } from '@/helper/types';
@ -89,6 +90,11 @@ export default class LlmNluHelper
}
async onApplicationBootstrap() {
if (!AppInstance.isReady()) {
// bypass in Test / CLI env
return;
}
try {
this.logger.log('Initializing LLM NLU helper, building prompts...');
// Build prompts for language and trait classifiers