larvitfiles
Advanced tools
Comparing version 2.1.0 to 2.2.0
@@ -7,2 +7,3 @@ 'use strict'; | ||
DbMigration = require('larvitdbmigration'), | ||
Intercom = require('larvitamintercom'), | ||
lUtils = require('larvitutils'), | ||
@@ -15,8 +16,8 @@ amsync = require('larvitamsync'), | ||
let readyInProgress = false, | ||
isReady = false, | ||
intercom; | ||
isReady = false; | ||
function listenToQueue(retries, cb) { | ||
const logPrefix = topLogPrefix + 'listenToQueue() - ', | ||
options = {'exchange': exports.exchangeName}; | ||
options = {'exchange': exports.exchangeName}, | ||
tasks = []; | ||
@@ -38,38 +39,32 @@ let listenMethod; | ||
if (exports.mode === 'master') { | ||
listenMethod = 'consume'; | ||
options.exclusive = true; // It is important no other client tries to sneak | ||
// out messages from us, and we want "consume" | ||
// since we want the queue to persist even if this | ||
// minion goes offline. | ||
} else if (exports.mode === 'slave' || exports.mode === 'noSync') { | ||
listenMethod = 'subscribe'; | ||
} else { | ||
const err = new Error('Invalid exports.mode. Must be either "master", "slave" or "noSync"'); | ||
log.error(logPrefix + err.message); | ||
return cb(err); | ||
} | ||
tasks.push(checkIntercom); | ||
tasks.push(checkMode); | ||
intercom = lUtils.instances.intercom; | ||
tasks.push(function (cb) { | ||
if (exports.mode === 'master') { | ||
listenMethod = 'consume'; | ||
options.exclusive = true; // It is important no other client tries to sneak | ||
// out messages from us, and we want "consume" | ||
// since we want the queue to persist even if this | ||
// minion goes offline. | ||
} else if (exports.mode === 'slave' || exports.mode === 'noSync') { | ||
listenMethod = 'subscribe'; | ||
} else { | ||
const err = new Error('Invalid exports.mode. Must be either "master", "slave" or "noSync"'); | ||
log.error(logPrefix + err.message); | ||
return cb(err); | ||
} | ||
if ( ! (intercom instanceof require('larvitamintercom')) && retries < 500) { | ||
retries ++; | ||
setTimeout(function () { | ||
listenToQueue(retries, cb); | ||
}, 50); | ||
return; | ||
} else if ( ! (intercom instanceof require('larvitamintercom'))) { | ||
log.error(logPrefix + 'Intercom is not set!'); | ||
return; | ||
} | ||
log.info(logPrefix + 'listenMethod: ' + listenMethod); | ||
log.info(logPrefix + 'listenMethod: ' + listenMethod); | ||
cb(); | ||
}); | ||
intercom.ready(function (err) { | ||
if (err) { | ||
log.error(logPrefix + 'intercom.ready() err: ' + err.message); | ||
return; | ||
} | ||
intercom[listenMethod](options, function (message, ack, deliveryTag) { | ||
tasks.push(function (cb) { | ||
exports.intercom.ready(cb); | ||
}); | ||
tasks.push(function (cb) { | ||
exports.intercom[listenMethod](options, function (message, ack, deliveryTag) { | ||
exports.ready(function (err) { | ||
@@ -94,4 +89,6 @@ ack(err); // Ack first, if something goes wrong we log it and handle it manually | ||
}); | ||
}, ready); | ||
}, cb); | ||
}); | ||
async.series(tasks, cb); | ||
} | ||
@@ -102,2 +99,62 @@ // Run listenToQueue as soon as all I/O is done, this makes sure the exports.mode can be set | ||
function checkIntercom(firstRun, cb) { | ||
const logPrefix = topLogPrefix + 'checkIntercom() - '; | ||
if (typeof firstRun === 'function') { | ||
cb = firstRun; | ||
firstRun = true; | ||
} else if (firstRun === undefined) { | ||
firstRun = true; | ||
cb = function () {}; | ||
} | ||
if (exports.intercom instanceof Intercom) { | ||
log.debug(logPrefix + 'exports.intercom is set, no modification needed'); | ||
} else if (lUtils.instances.intercom instanceof Intercom) { | ||
log.info(logPrefix + 'Using larvitutils.instances.intercom as Intercom'); | ||
exports.intercom = lUtils.instances.intercom; | ||
} else if (firstRun === false) { | ||
log.warn(logPrefix + 'Neither exports.intercom nor larvitutils.instances.intercom is an instance of Intercom. Fallback to create our own loopback interface.'); | ||
exports.intercom = new Intercom('loopback interface'); | ||
} else { | ||
// Give the app 50ms to sort this shit out before we use the fallback fallback | ||
setTimeout(function () { | ||
checkIntercom(false, cb); | ||
}, 50); | ||
return; | ||
} | ||
cb(); | ||
} | ||
function checkMode(firstRun, cb) { | ||
const logPrefix = topLogPrefix + 'checkMode() - '; | ||
if (typeof firstRun === 'function') { | ||
cb = firstRun; | ||
firstRun = true; | ||
} else if (firstRun === undefined) { | ||
firstRun = true; | ||
cb = function () {}; | ||
} | ||
if (exports.mode === 'slave' || exports.mode === 'master' || exports.mode === 'noSync') { | ||
log.debug(logPrefix + 'exports.mode is set, no modification needed'); | ||
} else if (lUtils.instances.dataWriterMode !== undefined) { | ||
log.info(logPrefix + 'Using larvitutils.instances.dataWriterMode as mode'); | ||
exports.mode = lUtils.instances.dataWriterMode; | ||
} else if (firstRun === false) { | ||
log.warn(logPrefix + 'Neither exports.mode nor larvitutils.instances.dataWriterMode is set to a valid string. Falling back to noSync.'); | ||
exports.mode = 'noSync'; | ||
} else { | ||
// Give the app 50ms to sort this shit out before we use the fallback fallback | ||
setTimeout(function () { | ||
checkMode(false, cb); | ||
}, 50); | ||
return; | ||
} | ||
cb(); | ||
} | ||
// This is ran before each incoming message on the queue is handeled | ||
@@ -128,24 +185,16 @@ function ready(retries, cb) { | ||
intercom = require('larvitutils').instances.intercom; | ||
readyInProgress = true; | ||
if ( ! (intercom instanceof require('larvitamintercom')) && retries < 10) { | ||
retries ++; | ||
setTimeout(function () { | ||
ready(retries, cb); | ||
}, 50); | ||
return; | ||
} else if ( ! (intercom instanceof require('larvitamintercom'))) { | ||
log.error(logPrefix + 'Intercom is not set!'); | ||
return; | ||
} | ||
tasks.push(checkIntercom); | ||
tasks.push(checkMode); | ||
readyInProgress = true; | ||
tasks.push(function (cb) { | ||
if (exports.mode === 'both' || exports.mode === 'slave') { | ||
log.verbose(logPrefix + 'exports.mode: "' + exports.mode + '", so read'); | ||
if (exports.mode === 'both' || exports.mode === 'slave') { | ||
log.verbose(logPrefix + 'exports.mode: "' + exports.mode + '", so read'); | ||
tasks.push(function (cb) { | ||
amsync.mariadb({'exchange': exports.exchangeName + '_dataDump'}, cb); | ||
}); | ||
} | ||
} else { | ||
cb(); | ||
} | ||
}); | ||
@@ -152,0 +201,0 @@ // Migrate database |
@@ -195,3 +195,3 @@ 'use strict'; | ||
utils.instances.intercom.send(message, options, function (err, msgUuid) { | ||
dataWriter.intercom.send(message, options, function (err, msgUuid) { | ||
if (err) return cb(err); | ||
@@ -242,3 +242,3 @@ dataWriter.emitter.once(msgUuid, cb); | ||
utils.instances.intercom.send(message, options, function (err, msgUuid) { | ||
dataWriter.intercom.send(message, options, function (err, msgUuid) { | ||
if (err) return cb(err); | ||
@@ -414,2 +414,2 @@ dataWriter.emitter.once(msgUuid, cb); | ||
exports.Files = Files; | ||
exports.getFileUuidBySlug = getFileUuidBySlug; | ||
exports.getFileUuidBySlug = getFileUuidBySlug; |
{ | ||
"name": "larvitfiles", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "Storage of files with an API and database to use in web environments", | ||
@@ -36,4 +36,4 @@ "main": "index.js", | ||
"larvitbase": "^1.1.6", | ||
"mocha": "^3.0.2" | ||
"mocha": "^4.0.1" | ||
} | ||
} |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
47921
22
1221
1
20