-
Notifications
You must be signed in to change notification settings - Fork 10
/
index.js
53 lines (40 loc) · 1.12 KB
/
index.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
const api = require('./lib/etherpad/api');
const subscriber = require('./lib/redis/subscriber');
const monitor = require('./lib/utils/monitor');
const server = require('./lib/express/server');
const Logger = require('./lib/utils/logger');
const prometheus = require('./lib/utils/prometheus');
const logger = new Logger('bbb-pads');
const RETRY = 10;
let retries = 0;
const fibonacci = (index) => {
if (index === 1) return 0;
if (index === 2) return 1;
return fibonacci(index - 1) + fibonacci(index - 2);
};
const abort = (error) => {
logger.fatal('abort', error);
process.exit(1);
};
const start = () => {
api.check().then(() => {
api.call('checkToken').then(() => {
subscriber.start();
server.start();
monitor.start();
prometheus.start();
}).catch(() => abort('key-mismatch'));
}).catch((error) => {
logger.warn('starting', error);
if (retries < RETRY) {
retries++;
setTimeout(() => {
logger.info('start', `retry ${retries} of ${RETRY}`);
start();
}, 1000 * fibonacci(retries));
} else {
abort('retry-exhausted');
}
});
};
start();