Skip to content

Commit edb3836

Browse files
committed
Fix structure + eslint
1 parent 92c7ef1 commit edb3836

File tree

3 files changed

+11
-104
lines changed

3 files changed

+11
-104
lines changed

src/_common/backend-initializer/config.initializer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ export default async function configInitializer(backendsPath: string): Promise<B
4343
}
4444
}
4545

46-
// logger.debug(backendsConfig)
46+
logger.verbose(backendsConfig);
4747
return backendsConfig;
4848
}

src/app.service.ts

Lines changed: 0 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,9 @@
11
import { Injectable, Logger } from '@nestjs/common';
2-
// import { Worker } from 'bullmq';
3-
// import { fdir } from 'fdir';
4-
// import * as fs from 'fs';
5-
// import * as YAML from 'yaml';
6-
// import * as process from 'child_process';
7-
// import * as mainProcess from 'process';
8-
// import * as path from 'path';
9-
// import { BackendConfigDto } from './backend-runner/_dto/Backend-config.dto';
10-
// import { BackendResultDto } from './backend-runner/_dto/Backend-result.dto';
11-
// import { plainToInstance } from 'class-transformer';
122
import { ConfigService } from '@nestjs/config';
13-
// import { spawnSync, exec } from 'child_process';
14-
// import executorTask from './_common/tasks/executor.task';
153

164
@Injectable()
175
export class AppService {
186
private readonly logger = new Logger(AppService.name);
19-
// backendsConfig: Array<BackendConfigDto> = [];
207

218
constructor(private readonly configService: ConfigService) {}
22-
23-
// async runDaemon() {
24-
// await this.loadConfig();
25-
// const backendResults = [];
26-
//
27-
// const worker = new Worker(
28-
// this.configService.get('nameQueue'),
29-
// async (job) => {
30-
// const results = [];
31-
// let gStatus = 0;
32-
// this.logger.log('start daemon');
33-
// for await (const backend of this.backendsConfig) {
34-
// if (job.name === 'LISTBACKEND') {
35-
// this.logger.log('execute LISTBACKEND');
36-
// return { jobId: job.id, status: 0, data: this.backendsConfig };
37-
// }
38-
// if (backend.active === 1) {
39-
// this.logger.log('Execute backend command ' + job.name + ' ' + backend.name);
40-
// const task = backend.actions[job.name];
41-
// this.logger.debug(backend.path + '/bin/' + task.exec);
42-
//
43-
// // const out2 = await executorTask(backend.path +'/bin/'+ task.exec, job)
44-
// // console.log('out2', out2)
45-
// const out = process.spawnSync(backend.path + '/bin/' + task.exec, [], {
46-
// shell: 'powershell.exe',
47-
// input: JSON.stringify(job.data),
48-
// });
49-
//
50-
// gStatus += out.status;
51-
// const result = new BackendResultDto();
52-
// result.backend = backend.name;
53-
// result.status = out.status;
54-
// result.output = out.stdout?.toString();
55-
// // console.log('result', result, out, out.error)
56-
// result.error = out.stderr?.toString();
57-
// results.push(result);
58-
// if (task.onError === 'stop' && out.status != 0) {
59-
// this.logger.log('stop on Error ');
60-
// break;
61-
// }
62-
// }
63-
// }
64-
// this.logger.debug('results : ');
65-
// this.logger.debug(results);
66-
// return { jobId: job.id, status: gStatus, data: results };
67-
// },
68-
// { connection: this.configService.get('redis') },
69-
// );
70-
// }
71-
//
72-
// async loadConfig() {
73-
// this.logger.log('load backends config');
74-
// const crawler = new fdir().withBasePath().filter((path, isDirectory) => path.endsWith('.yml'));
75-
// const files = crawler.crawl(this.configService.get('backendsPath')).sync().sort();
76-
// for await (const element of files) {
77-
// this.logger.log('Load ' + element);
78-
// const file = fs.readFileSync(element, 'utf8');
79-
// const config = YAML.parse(file);
80-
// try {
81-
// const verif = plainToInstance(BackendConfigDto, config);
82-
// } catch (e) {
83-
// //const erreurs=errors.map((e) => e.toString()).join(', ')
84-
// //this.logger.fatal(`Erreur fichier de configuration : ${element} : ${erreurs}` )
85-
// mainProcess.exit(1);
86-
// }
87-
// config.path = path.dirname(element);
88-
// this.backendsConfig.push(config);
89-
// this.logger.log('Loaded ' + config.name);
90-
// }
91-
// this.logger.debug(this.backendsConfig);
92-
// }
939
}

src/main.ts

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ declare const module: any;
88
const app = await NestFactory.createApplicationContext(AppModule, {
99
logger: await setLogLevel(),
1010
});
11+
await app.init();
1112

1213
if (module.hot) {
1314
module.hot.accept();
@@ -16,24 +17,14 @@ declare const module: any;
1617
})();
1718

1819
async function setLogLevel(): Promise<LogLevel[]> {
19-
let loggerOptions: LogLevel[] = ['error', 'warn', 'fatal'];
2020
const config = await configInstance();
21-
switch (config['logLevel']) {
22-
case 'fatal':
23-
loggerOptions = ['fatal'];
24-
break;
25-
case 'error':
26-
loggerOptions = ['error', 'fatal'];
27-
break;
28-
case 'warn':
29-
loggerOptions = ['error', 'warn', 'fatal'];
30-
break;
31-
case 'info':
32-
loggerOptions = ['error', 'warn', 'fatal', 'log', 'verbose'];
33-
break;
34-
case 'debug':
35-
loggerOptions = ['error', 'warn', 'fatal', 'log', 'verbose', 'debug'];
36-
break;
37-
}
38-
return loggerOptions;
21+
const logLevelMap: Record<LogLevel | string, LogLevel[]> = {
22+
fatal: ['fatal'],
23+
error: ['error', 'fatal'],
24+
warn: ['error', 'fatal', 'warn'],
25+
info: ['error', 'fatal', 'warn', 'log'],
26+
debug: ['error', 'fatal', 'warn', 'log', 'debug'],
27+
verbose: ['error', 'fatal', 'warn', 'log', 'debug', 'verbose'],
28+
};
29+
return logLevelMap[config.logLevel] || logLevelMap['warn'];
3930
}

0 commit comments

Comments
 (0)