-
Notifications
You must be signed in to change notification settings - Fork 3
/
oracle.js
48 lines (42 loc) · 1.09 KB
/
oracle.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
const testContract = require('../shared/test-contract');
const util = require('util');
const sleep = util.promisify(setTimeout);
const loggerMaker = require('../config/logger.js');
const logger = loggerMaker.getLogger('test-oracle');
const sleepInterval = 1000 * 60 * 60 * 24; // 1 day
class TESTOracle {
constructor() {
this.normalSleepInterval = sleepInterval;
this.errorSleepInterval = sleepInterval;
}
async prepare() {
logger.info('service started');
}
async iterate() {
logger.info('iteration started');
await testContract.reward();
logger.info('iteration finished');
return {nonStop: false};
};
async run() {
try {
await this.prepare();
} catch (e) {
logger.error(e);
process.exit(-1);
}
while (true) {
try {
const {nonStop} = await this.iterate();
if (!nonStop) {
await sleep(this.normalSleepInterval);
}
} catch (e) {
logger.error(e);
await sleep(this.errorSleepInterval);
}
}
}
}
const testOracle = new TESTOracle();
module.export = testOracle.run();