Merge in sane vs gaze stuff

This commit is contained in:
Bryan Ashby 2017-10-02 21:10:25 -06:00
commit 68c6197732
4 changed files with 39 additions and 21 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);
}); });

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
@ -215,7 +216,7 @@ EventSchedulerModule.prototype.startup = function(cb) {
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'
); );
@ -227,11 +228,20 @@ EventSchedulerModule.prototype.startup = function(cb) {
} }
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');
@ -1683,10 +1683,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

@ -26,7 +26,6 @@
"exiftool": "^0.0.3", "exiftool": "^0.0.3",
"farmhash": "^2.0.4", "farmhash": "^2.0.4",
"fs-extra": "^4.0.1", "fs-extra": "^4.0.1",
"gaze": "^1.1.2",
"graceful-fs": "^4.1.11", "graceful-fs": "^4.1.11",
"hashids": "^1.1.1", "hashids": "^1.1.1",
"hjson": "^3.1.0", "hjson": "^3.1.0",
@ -40,6 +39,7 @@
"node-glob": "^1.2.0", "node-glob": "^1.2.0",
"nodemailer": "^4.1.0", "nodemailer": "^4.1.0",
"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.9", "sqlite3": "^3.1.9",
"sqlite3-trans" : "^1.2.0", "sqlite3-trans" : "^1.2.0",