-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
67 lines (52 loc) · 1.76 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
58
59
60
61
62
63
64
65
66
67
'use strict';
const nconf = require('nconf');
const path = require('path');
const Future = require('fluture');
// const heapdump = require('heapdump');
const { pipe, map, tap } = require('ramda');
const cfg = nconf
.argv()
.env()
.file('stage', path.resolve(__dirname, 'config/', 'env-' + nconf.get('NODE_ENV') + '.json'))
.file(path.resolve(__dirname, 'config/', 'config.json'));
/* cfg.defaults({
}); */
cfg.required(['job']);
/**
* MongoStream
*
*/
const MongoStream = require('./lib/MongoStream');
/**
* entrance of the program for each job
*/
const entrance = require(`./jobs/${cfg.get('job')}/${cfg.get('job')}.js`);
/** load
* Any -> Future a b
*
*/
const loadToCsv = require('./lib/load/CsvStream.js');
const loadToMongo = require('./lib/load/MongoLoadStream');
const load = cfg.get(`jobs:${cfg.get('job')}:output:type`) === 'mongodb' ?
new loadToMongo({
url: cfg.get(`jobs:${cfg.get('job')}:output:url`),
db: cfg.get(`jobs:${cfg.get('job')}:output:db`),
collection: cfg.get(`jobs:${cfg.get('job')}:output:collection`),
key: cfg.get(`jobs:${cfg.get('job')}:output:key`),
updateKeys: cfg.get(`jobs:${cfg.get('job')}:output:updateKeys`),
insertKeys: cfg.get(`jobs:${cfg.get('job')}:output:insertKeys`),
op: cfg.get(`jobs:${cfg.get('job')}:output:op`)
}) : new loadToCsv({
dir: cfg.get(`jobs:${cfg.get('job')}:output:dir`),
name: cfg.get(`jobs:${cfg.get('job')}:output:name`),
fields: cfg.get(`jobs:${cfg.get('job')}:output:fields`)
});
const stream = new MongoStream({
connection: cfg.get(`jobs:${cfg.get('job')}:input:connection`),
db: cfg.get(`jobs:${cfg.get('job')}:input:db`),
collection: cfg.get(`jobs:${cfg.get('job')}:input:collection`),
op: cfg.get(`jobs:${cfg.get('job')}:input:op`),
load
});
load.init();
entrance(stream, load);