-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patholdData.js
More file actions
53 lines (43 loc) · 1.2 KB
/
oldData.js
File metadata and controls
53 lines (43 loc) · 1.2 KB
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
var logger = require('./services/logger.js')
var models = require('./models');
var fs = require('fs'),
readline = require('readline');
var walk = require('walk');
var files = [];
var lineReader = [];
var json = [];
var checkLogs = function (callback) {
console.log('checking logs ... every 20 sec');
// Walker options
var walker = walk.walk('logs', {followLinks: false});
walker.on('file', function (root, stat, next) {
// Add this file to the list of files
files.push(root + '/' + stat.name);
next();
});
walker.on('end', function () {
for (var x in files) {
var fileName = files[x];
lineReader[x] = readline.createInterface({
input: fs.createReadStream(fileName),
output: process.stdout,
terminal: false
});
lineReader[x].on('line', function (line) {
// handle line of every fileName
json.push(line);
callback(line);
});
}
});
}
checkLogs(function (line) {
models.sequelize.transaction(function (t) {
return models.stream.create({
row: JSON.parse(JSON.parse(line).message)
}
, {transaction: t}).then(function (stream) {
console.log("Done: " + stream)
});
});
});