-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.js
76 lines (42 loc) · 1.42 KB
/
run.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
const SETTINGS = require('./settings.json');
const HANA = require('./hana');
const FS = require('fs');
const PATH = require('path');
Object.keys(SETTINGS.jobs).map(job_name => {
let job = SETTINGS.jobs[job_name];
let sql = job.sql || job.file && FS.readFileSync(PATH.join('./', job.file), { encoding: 'utf8' })
let postSQL = job.postSQL
setInterval((name, query, postSQL) => {
HANA.dispatch(name, query, postSQL)
}, job.interval, job_name, sql, postSQL)
})
process.on('SIGINT', function() {
HANA.shutdown(() => {
let reporFile = 'job_report_' + Date.now() + '.csv';
let report = HANA.report();
saveReport(report, './' + reporFile);
console.log("\n\nJOB REPORT:", report);
console.log(`Отчет сохранён в файле: ${reporFile}`);
process.exit();
})
});
function saveReport(report, path) {
let data = [];
let headers = undefined;
Object.keys(report).map(k => {
data.push("\r\n\r\n" + k);
if (report[k].length > 0) {
headers = Object.keys(report[k][0])
data.push(headers.join(';'));
report[k].map(j => {
data.push(
headers.map(h => j[h]).join(';')
);
});
}
else {
data.push("[EMPTY]\n");
}
});
FS.writeFileSync(path, data.join("\r\n"));
}