Skip to content

Commit

Permalink
* add some more debugging on redis connections
Browse files Browse the repository at this point in the history
* enhance error handling for file write logic
  • Loading branch information
Apollon77 committed Nov 12, 2019
1 parent 2f59557 commit 3a013ef
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 10 deletions.
37 changes: 27 additions & 10 deletions lib/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -1572,10 +1572,14 @@ function processCommand(command, args, params, callback) {
const path = (args[2] || process.cwd()).replace(/\\/g, '/').split('/');
const file = path[path.length - 1];
if (!file.match(/\.[a-zA-Z0-9]+$/)) { // If destination location seems to be a directory, add filename
path.push(parts[parts.length - 1]);
if (file !== '') {
path.push(parts[parts.length - 1]);
} else { // trailing slash
path[path.length - 1] = parts[parts.length - 1];
}
}
let adapt = parts.shift();
if (!adapt) {
if (!adapt) { // leading slash
adapt = parts.shift();
}
objects.readFile(adapt, parts.join('/'), (err, data) => {
Expand All @@ -1593,26 +1597,39 @@ function processCommand(command, args, params, callback) {

const path = args[2].replace(/\\/g, '/').split('/');

let adapt = path.shift();
if (!adapt) {
adapt = path.shift();
}
if (!path.length) {
path.push('');
}

let fileSrc = parts[parts.length - 1];
let fileDest = path[parts.length - 1];
let fileDest = path[path.length - 1];
if (!fileDest.match(/\.[a-zA-Z0-9]+$/)) { // last portion of destination has no extension, consider being a directory
fileDest = "";
}
if (!fileSrc || !fs.existsSync(toRead)) {
console.log('Please provide a valid file name as source file');
return void callback(1);
}
const srcStat = fs.statSync(toRead);
if (!srcStat.isFile()) {
console.log('Please provide a valid file name as source file');
return void callback(1);
}
if (!fileDest) { // destination filename is not given, use same name as source file
fileDest = fileSrc;
}
if (fileDest !== path[parts.length - 1]) { // if last part of path is different then filename, add filename
path.push(fileDest);
}
let adapt = path.shift();
if (!adapt) {
adapt = path.shift();
if (fileDest !== path[path.length - 1]) { // if last part of path is different then filename, add filename
if (path[path.length - 1] !== '') {
path.push(fileDest);
} else { // trailing slash
path[path.length - 1] = fileDest;
}
}
const destFilename = path.join('/');
const destFilename = path.length ? path.join('/') : '/';
const data = fs.readFileSync(toRead);

objects.writeFile(adapt, destFilename, data, _err => {
Expand Down
16 changes: 16 additions & 0 deletions lib/states/statesInRedis.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ class StateRedis {
}

if (!this.sub) {
this.log.debug(this.namespace + ' States create PubSub Client');
this.sub = new Redis(this.settings.connection.options);

if (typeof onChange === 'function') {
Expand Down Expand Up @@ -263,6 +264,21 @@ class StateRedis {
if (this.settings.connection.enhancedLogging) this.log.silly(this.namespace + ' Sub-Client States No redis connection: ' + JSON.stringify(error));
});

if (this.settings.connection.enhancedLogging) {
this.sub.on('connect', () => {
this.log.silly(this.namespace + ' PubSub client States-Redis Event connect (stop=' + this.stop + ')');
});

this.client.on('close', () => {
this.log.silly(this.namespace + ' PubSub client States-Redis Event close (stop=' + this.stop + ')');
});

this.client.on('reconnecting', (reconnectCounter) => {
this.log.silly(this.namespace + ' PubSub client States-Redis Event reconnect (reconnectCounter=' + reconnectCounter + ', stop=' + this.stop + ')');
});
}


this.sub.on('ready', _error => {
this.sub.subscribe('__keyevent@' + this.settings.connection.options.db + '__:expired', err => {
err && this.log.warn('Unable to subscribe to expiry Keyspace events from Redis Server: ' + err)
Expand Down

0 comments on commit 3a013ef

Please sign in to comment.