const each = require('async/each')
const eachLimit = require('async/eachLimit')
const waterfall = require('async/waterfall')
+const values = require('lodash/values')
const constants = require('../initializers/constants')
const logger = require('../helpers/logger')
const Request = sequelize.define('Request',
{
request: {
- type: DataTypes.JSON
+ type: DataTypes.JSON,
+ allowNull: false
},
endpoint: {
- // TODO: enum?
- type: DataTypes.STRING
+ type: DataTypes.ENUM(values(constants.REQUEST_ENDPOINTS)),
+ allowNull: false
}
},
{
timer = null
}
-function flush () {
+function flush (callback) {
removeAll.call(this, function (err) {
if (err) logger.error('Cannot flush the requests.', { error: err })
+
+ return callback(err)
})
}
'Error sending secure request to %s pod.',
toPod.host,
{
- error: err || new Error('Status code not 20x : ' + res.statusCode)
+ error: err ? err.message : 'Status code not 20x : ' + res.statusCode
}
)
makeRequest(toPod, requestToMake.endpoint, requestToMake.datas, function (success) {
if (success === true) {
- logger.debug('Removing requests for %s pod.', requestToMake.toPodId, { requestsIds: requestToMake.ids })
+ logger.debug('Removing requests for pod %s.', requestToMake.toPodId, { requestsIds: requestToMake.ids })
goodPods.push(requestToMake.toPodId)
if (goodPods.length !== 0) {
Pod.incrementScores(goodPods, constants.PODS_SCORE.BONUS, function (err) {
- if (err) logger.error('Cannot increment scores of good pods.')
+ if (err) logger.error('Cannot increment scores of good pods.', { error: err })
})
}
if (badPods.length !== 0) {
Pod.incrementScores(badPods, constants.PODS_SCORE.MALUS, function (err) {
- if (err) logger.error('Cannot decrement scores of bad pods.')
+ if (err) logger.error('Cannot decrement scores of bad pods.', { error: err })
removeBadPods.call(self)
})
}
function removeAll (callback) {
// Delete all requests
- this.destroy({ truncate: true }).asCallback(callback)
+ this.truncate({ cascade: true }).asCallback(callback)
}
function removeWithEmptyTo (callback) {