-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
57 lines (50 loc) · 1.22 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
54
55
56
57
const startCronJobs = require('./cron');
const {getModel} = require('./db');
const createTasks = require('./lib/task');
const abiHelper = require('./lib/abi');
const {newLog} = require('./lib/utils');
const defaultLoggerFactory = newLog('ortpearl');
async function create(conf) {
const {
loggerFactory = defaultLoggerFactory,
tasks,
abis,
taskCtx,
taskNamespace,
maxConfirmCount,
nodes,
mongoUrl,
engineDbName
} = conf;
const logger = loggerFactory('engine');
// create tasks
const {mergeTasks, rawTasks} = await createTasks(
tasks,
abis,
taskCtx,
taskNamespace
);
// init db models
const dbModels = await getModel(mongoUrl, engineDbName);
logger.debug('init db models done.');
// init channels
const channelIds = await dbModels.Channel.initChannels(rawTasks);
const channels = channelIds.map((channelId, idx) => ({channelId, task: rawTasks[idx]}));
logger.debug('init channels done.');
const stopCronJobs = await startCronJobs({
maxConfirmCount,
logger,
mergeTasks,
channels,
dbModels,
nodes
});
logger.debug('cron jobs done.');
return () => {
stopCronJobs();
};
}
module.exports = {
startEngine: create,
abiHelper
};