* Switch to sane over gaze for file watching: Gaze was not triggering on file additions

* Remove watching of config files for now -- doesn't work anyway. Will revisit later.
This commit is contained in:
Bryan Ashby 2017-10-02 21:06:53 -06:00
parent d5334270c4
commit 067bb9e884
4 changed files with 43 additions and 24 deletions

View file

@ -6,7 +6,6 @@ var Log = require('./logger.js').log;
var paths = require('path'); var paths = require('path');
var fs = require('graceful-fs'); var fs = require('graceful-fs');
var Gaze = require('gaze').Gaze;
var events = require('events'); var events = require('events');
var util = require('util'); var util = require('util');
var assert = require('assert'); var assert = require('assert');
@ -18,7 +17,7 @@ function ConfigCache() {
var self = this; var self = this;
this.cache = {}; // filePath -> HJSON this.cache = {}; // filePath -> HJSON
this.gaze = new Gaze(); //this.gaze = new Gaze();
this.reCacheConfigFromFile = function(filePath, cb) { this.reCacheConfigFromFile = function(filePath, cb) {
fs.readFile(filePath, { encoding : 'utf-8' }, function fileRead(err, data) { fs.readFile(filePath, { encoding : 'utf-8' }, function fileRead(err, data) {
@ -32,7 +31,7 @@ function ConfigCache() {
}); });
}; };
/*
this.gaze.on('error', function gazeErr(err) { this.gaze.on('error', function gazeErr(err) {
}); });
@ -50,6 +49,7 @@ function ConfigCache() {
} }
}); });
}); });
*/
} }
@ -58,13 +58,13 @@ util.inherits(ConfigCache, events.EventEmitter);
ConfigCache.prototype.getConfigWithOptions = function(options, cb) { ConfigCache.prototype.getConfigWithOptions = function(options, cb) {
assert(_.isString(options.filePath)); assert(_.isString(options.filePath));
var self = this; // var self = this;
var isCached = (options.filePath in this.cache); var isCached = (options.filePath in this.cache);
if(options.forceReCache || !isCached) { if(options.forceReCache || !isCached) {
this.reCacheConfigFromFile(options.filePath, function fileCached(err, config) { this.reCacheConfigFromFile(options.filePath, function fileCached(err, config) {
if(!err && !isCached) { if(!err && !isCached) {
self.gaze.add(options.filePath); //self.gaze.add(options.filePath);
} }
cb(err, config, true); cb(err, config, true);
}); });
@ -82,4 +82,4 @@ ConfigCache.prototype.getModConfig = function(fileName, cb) {
this.getConfig(paths.join(Config.paths.mods, fileName), cb); this.getConfig(paths.join(Config.paths.mods, fileName), cb);
}; };
module.exports = exports = new ConfigCache(); module.exports = exports = new ConfigCache();

View file

@ -10,8 +10,9 @@ const _ = require('lodash');
const later = require('later'); const later = require('later');
const path = require('path'); const path = require('path');
const pty = require('ptyw.js'); const pty = require('ptyw.js');
const gaze = require('gaze'); const sane = require('sane');
const moment = require('moment'); const moment = require('moment');
const paths = require('path');
exports.getModule = EventSchedulerModule; exports.getModule = EventSchedulerModule;
exports.EventSchedulerModule = EventSchedulerModule; // allow for loadAndStart exports.EventSchedulerModule = EventSchedulerModule; // allow for loadAndStart
@ -209,13 +210,13 @@ EventSchedulerModule.prototype.startup = function(cb) {
Log.warn( { eventName : schedEvent.name }, 'Invalid scheduled event entry'); Log.warn( { eventName : schedEvent.name }, 'Invalid scheduled event entry');
return; return;
} }
Log.debug( Log.debug(
{ {
eventName : schedEvent.name, eventName : schedEvent.name,
schedule : this.moduleConfig.events[schedEvent.name].schedule, schedule : this.moduleConfig.events[schedEvent.name].schedule,
action : schedEvent.action, action : schedEvent.action,
next : moment(later.schedule(schedEvent.schedule.sched).next(1)).format('ddd, MMM Do, YYYY @ h:m:ss a') next : schedEvent.schedule.sched ? moment(later.schedule(schedEvent.schedule.sched).next(1)).format('ddd, MMM Do, YYYY @ h:m:ss a') : 'N/A',
}, },
'Scheduled event loaded' 'Scheduled event loaded'
); );
@ -226,12 +227,21 @@ EventSchedulerModule.prototype.startup = function(cb) {
}, schedEvent.schedule.sched)); }, schedEvent.schedule.sched));
} }
if(schedEvent.schedule.watchFile) { if(schedEvent.schedule.watchFile) {
gaze(schedEvent.schedule.watchFile, (err, watcher) => { const watcher = sane(
// :TODO: should track watched files & stop watching @ shutdown paths.dirname(schedEvent.schedule.watchFile),
watcher.on('all', (watchEvent, watchedPath) => { {
if(schedEvent.schedule.watchFile === watchedPath) { glob : `**/${paths.basename(schedEvent.schedule.watchFile)}`
self.performAction(schedEvent, `Watch file: ${watchedPath}`); }
);
// :TODO: should track watched files & stop watching @ shutdown?
[ 'change', 'add', 'delete' ].forEach(event => {
watcher.on(event, (fileName, fileRoot) => {
const eventPath = paths.join(fileRoot, fileName);
if(schedEvent.schedule.watchFile === eventPath) {
self.performAction(schedEvent, `Watch file: ${eventPath}`);
} }
}); });
}); });

View file

@ -30,7 +30,7 @@ const fs = require('graceful-fs');
const later = require('later'); const later = require('later');
const temptmp = require('temptmp').createTrackedSession('ftn_bso'); const temptmp = require('temptmp').createTrackedSession('ftn_bso');
const assert = require('assert'); const assert = require('assert');
const gaze = require('gaze'); const sane = require('sane');
const fse = require('fs-extra'); const fse = require('fs-extra');
const iconv = require('iconv-lite'); const iconv = require('iconv-lite');
const uuidV4 = require('uuid/v4'); const uuidV4 = require('uuid/v4');
@ -1654,10 +1654,18 @@ FTNMessageScanTossModule.prototype.startup = function(cb) {
} }
if(_.isString(importSchedule.watchFile)) { if(_.isString(importSchedule.watchFile)) {
gaze(importSchedule.watchFile, (err, watcher) => { const watcher = sane(
watcher.on('all', (event, watchedPath) => { paths.dirname(importSchedule.watchFile),
if(importSchedule.watchFile === watchedPath) { {
tryImportNow(`Performing import/toss due to @watch: ${watchedPath} (${event})`); glob : `**/${paths.basename(importSchedule.watchFile)}`
}
);
[ 'change', 'add', 'delete' ].forEach(event => {
watcher.on(event, (fileName, fileRoot) => {
const eventPath = paths.join(fileRoot, fileName);
if(paths.join(fileRoot, fileName) === importSchedule.watchFile) {
tryImportNow(`Performing import/toss due to @watch: ${eventPath} (${event})`);
} }
}); });
}); });

View file

@ -23,9 +23,11 @@
"binary": "0.3.x", "binary": "0.3.x",
"buffers": "NuSkooler/node-buffers", "buffers": "NuSkooler/node-buffers",
"bunyan": "^1.8.10", "bunyan": "^1.8.10",
"exiftool": "^0.0.3",
"farmhash": "^1.2.1", "farmhash": "^1.2.1",
"fs-extra": "^3.0.1", "fs-extra": "^3.0.1",
"gaze": "^1.1.2", "gaze": "^1.1.2",
"graceful-fs": "^4.1.11",
"hashids": "^1.1.1", "hashids": "^1.1.1",
"hjson": "^2.4.2", "hjson": "^2.4.2",
"iconv-lite": "^0.4.17", "iconv-lite": "^0.4.17",
@ -35,18 +37,17 @@
"mime-types": "^2.1.15", "mime-types": "^2.1.15",
"minimist": "1.2.x", "minimist": "1.2.x",
"moment": "^2.18.1", "moment": "^2.18.1",
"node-glob": "^1.2.0",
"nodemailer": "^4.0.1", "nodemailer": "^4.0.1",
"ptyw.js": "NuSkooler/ptyw.js", "ptyw.js": "NuSkooler/ptyw.js",
"sane": "^2.2.0",
"sanitize-filename": "^1.6.1", "sanitize-filename": "^1.6.1",
"sqlite3": "^3.1.1", "sqlite3": "^3.1.1",
"ssh2": "^0.5.5", "ssh2": "^0.5.5",
"temptmp": "^1.0.0", "temptmp": "^1.0.0",
"uuid": "^3.0.1", "uuid": "^3.0.1",
"uuid-parse": "^1.0.0", "uuid-parse": "^1.0.0",
"ws" : "^3.0.0", "ws": "^3.0.0"
"graceful-fs" : "^4.1.11",
"exiftool" : "^0.0.3",
"node-glob" : "^1.2.0"
}, },
"devDependencies": {}, "devDependencies": {},
"engines": { "engines": {