-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathimporter.js
111 lines (99 loc) · 2.3 KB
/
importer.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
var fs = require("fs");
var path = require("path");
var ogi = require("./index");
var currentImporter = process.argv[2];
var IMPORTERS = {
"bills": {
Klass: ogi.BillImporter,
storerOptions: {
deph: 2
}
},
"committees": {
Klass: ogi.CommitteeImporter,
storerOptions: {
deph: 0
}
},
"people": {
Klass: ogi.PeopleImporter,
storerOptions: {
deph: 0
}
},
"vote": {
Klass: ogi.VoteImporter,
storerOptions: {
deph: 0
}
},
"events": {
Klass: ogi.EventsImporter,
storerOptions: {
deph: 0
}
}
};
var Importer = IMPORTERS[currentImporter];
if (!Importer) {
if (currentImporter) {
console.log("Importer '" + currentImporter + "' does not exist. " +
"Supported importers are:");
} else {
console.log("Importer not specified. Supported importers are:");
}
for (var property in IMPORTERS) {
console.log(" " + property);
}
return;
}
var LOG = (function () {
var winston = require("winston");
var logger = winston.Logger({
transports: [
new winston.transports.File({ filename: 'importer.log' })
]
});
return winston;
}());
var QUERY_CACHE_DIR = (function () {
var dataDir = path.join(__dirname, "data");
var cache = path.join(__dirname, "data", "cache");
if (!fs.existsSync(dataDir)) {
fs.mkdirSync(dataDir);
}
if (!fs.existsSync(cache)) {
fs.mkdirSync(cache);
}
return cache;
}());
var DATA_DIR = (function () {
var dataDir = path.join(__dirname, "data", currentImporter);
if (!fs.existsSync(dataDir)) {
fs.mkdirSync(dataDir);
}
return dataDir;
}());
var inMemoryStorer = new ogi.InMemoryStorer();
var importer = new Importer.Klass({
startPage: 0,
poolSize: 4,
pageSize: 1000,
logger: LOG,
role: currentImporter,
queryCache: new ogi.FileSystemCache(QUERY_CACHE_DIR),
storers: [
inMemoryStorer,
new ogi.FileSystemStorer(DATA_DIR, Importer.storerOptions)
]
});
LOG.info("Process PID: " + process.pid);
LOG.info("Storing data to: " + DATA_DIR);
var start = new Date().getTime();
importer.start(function (err, terminated) {
console.log("Imported items: " + inMemoryStorer.getNumberOfItems(),
"Elapsed time: " + ((new Date().getTime() - start)) / 1000) + " secs.";
if (terminated) {
console.log("Import process finished.");
}
});