|
1 | 1 | 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'; |
12 | 2 | import { ConfigService } from '@nestjs/config'; |
13 | | -// import { spawnSync, exec } from 'child_process'; |
14 | | -// import executorTask from './_common/tasks/executor.task'; |
15 | 3 |
|
16 | 4 | @Injectable() |
17 | 5 | export class AppService { |
18 | 6 | private readonly logger = new Logger(AppService.name); |
19 | | - // backendsConfig: Array<BackendConfigDto> = []; |
20 | 7 |
|
21 | 8 | 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 | | - // } |
93 | 9 | } |
0 commit comments