-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
38 lines (32 loc) · 1.05 KB
/
server.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
var fs = require('fs');
var cp = require('child_process');
var queue = require('block-queue');
var montage = require('./montage.js');
function processFile(filename, done) {
console.log("process "+filename);
montage.processFile(filename, done);
}
////////////////////////////////////////////////////////////////////////
//
// test code to check directory for xml file changes, and process them
// while a file is being processed, new ones are waiting in queue
//
////////////////////////////////////////////////////////////////////////
var w = undefined;
var prefix = "/tmp";
var ext = ".xml";
var q = queue(1, function(task, done) {
try {
processFile(prefix + "/" + task, done);
} catch(error) {
done();
console.log("error in processing: "+error);
}
});
function handleFileChange(eventType, filename) {
if (filename && filename.indexOf(ext)>-1 && eventType == 'change') {
console.log('eventType: '+eventType+", filename: "+filename);
q.push(filename);
};
}
w = fs.watch(prefix, {encoding: 'buffer'}, handleFileChange);