This repository was archived by the owner on Oct 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.js
64 lines (55 loc) · 1.74 KB
/
main.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
var config = require('./config.js');
var services = require('./src/services.js');
var pipeline = require('./src/pipeline.js');
var utils = require('./src/utils.js');
var fields = require('./fields.js');
var db = require('./src/db/mysqldb.js')();
/*
* Function that adds some new ECMAScript 6 features to common classes.
*/
function hackClasses() {
if (!String.prototype.startsWith) {
String.prototype.startsWith = function(searchString, position) {
position = position || 0;
return this.indexOf(searchString, position) === position;
};
}
if (!String.prototype.endsWith) {
String.prototype.endsWith = function(searchString, position) {
var subjectString = this.toString();
if (position === undefined || position > subjectString.length) {
position = subjectString.length;
}
position -= searchString.length;
var lastIndex = subjectString.indexOf(searchString, position);
return lastIndex !== -1 && lastIndex === position;
};
}
}
var base;
try {
hackClasses();
var schema = fields.getQmSchema();
log.info('Opening database ...');
if (log.trace())
log.trace('Using the following schema: %s', JSON.stringify(schema));
base = new qm.Base({
dbPath: config.REAL_TIME_BASE_PATH,
schema: schema,
mode: config.QM_DATABASE_MODE,
strictNames: false
});
if (config.QM_CREATE_PIPELINE) {
log.info('Initializing pipeline ...');
pipeline.init({ base: base, db: db });
}
services.init({ base: base, pipeline: pipeline, db: db });
log.info('Registering signal handlers ...');
log.info('Registering SIGINT handler ...');
process.on("SIGINT", function () {
utils.exit(base);
});
} catch (e) {
log.error(e, 'Exception in main!');
utils.exit(base);
}