-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
62 lines (44 loc) · 1.58 KB
/
main.js
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
require('dotenv').config();
const { startRedis } = require('./services/redis');
const DiscordClient = require('./discord');
const { TelegramClient } = require('./telegram');
const APIServer = require('./api');
const logger = require('./logger');
const { fetchCurrenciesList } = require('./services/currency');
function main() {
let app = {};
app.logger = require('./logger').child({ module: 'index' });
app.redis = startRedis();
fetchCurrenciesList().then(currencies_list => {
if (currencies_list !== null) {
app.currencies_list = currencies_list;
}
});
// update daily
setInterval(() => fetchCurrenciesList(), 24 * 60 * 60 * 1000);
app.discord_client = new DiscordClient(app);
app.telegram_client = new TelegramClient(app);
app.api_server = new APIServer(app);
app.logger.info('Starting Discord Client...');
app.discord_client.start();
app.logger.info('Starting Telegram Client...');
app.telegram_client.start();
app.logger.info('Starting API...');
app.api_server.start();
return app;
}
let app = main();
process_logger = logger.child({ module: 'process' });
process.on('warning', (warning) => {
process_logger.warn(warning.message);
});
// process.on('uncaughtException', (error) => {
// process_logger.error('Got unhandledException:', error);
// });
process.on('beforeExit', async () => {
process_logger.info('Gracefully shutdowning application...');
await app?.discord_client?.stop();
await app?.telegram_client?.stop();
await app?.api_server?.stop();
process.exit();
});