-
Notifications
You must be signed in to change notification settings - Fork 179
Expand file tree
/
Copy pathapp.ts
More file actions
42 lines (35 loc) · 1.6 KB
/
Copy pathapp.ts
File metadata and controls
42 lines (35 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { AISuggestionService } from './helpers/suggestions.js';
import { aiSuggestionsAPI } from './api/service/ai-suggestions-service.js';
import { AISuggestionsDB } from './helpers/ai-suggestions-db.js';
import { AIManager } from './ai-manager.js';
import { ApplicationState, JwtServicesValidator, MessageBrokerChannel, mongoForLoggingInitialization, OldSecretManager, PinoLogger, pinoLoggerInitialization } from '@guardian/common';
import * as process from 'node:process';
import { ApplicationStates } from '@guardian/interfaces';
Promise.all([
MessageBrokerChannel.connect('AI_SERVICE'),
mongoForLoggingInitialization()
]).then(async values => {
const [cn, loggerMongo] = values;
const logger: PinoLogger = pinoLoggerInitialization(loggerMongo);
await new OldSecretManager().setConnection(cn).init();
const jwtServiceName = 'AI_SERVICE';
JwtServicesValidator.setServiceName(jwtServiceName);
const state = new ApplicationState();
await state.setServiceName('AI_SERVICE').setConnection(cn).init();
await state.updateState(ApplicationStates.INITIALIZING);
await new AISuggestionService().setConnection(cn).init();
await new AISuggestionsDB().setConnection(cn).init();
try {
const aiManager = new AIManager(logger);
await aiSuggestionsAPI(aiManager, logger);
await state.updateState(ApplicationStates.READY);
await logger.info('Ai service started', ['AI_SERVICE']);
} catch (error) {
console.log(error);
console.error(error);
process.exit(0);
}
}, (reason) => {
console.log(reason);
process.exit(0);
});