# xCALLY MOTION Changelog
+- * 1ba79fa - 2016-09-16: Added cleaner for all channels
- * 82c5e19 - 2016-09-16: remove custom label from mail selection (scheduler)
- * b1ef54a - 2016-09-16: fix service mail account
- * 6ae85eb - 2016-09-16: fixed enquiry forward after smtp changes (service)
var _ = require('lodash');
var Promise = require('bluebird');
-var ReportQueue = require('../../models').ReportQueue;
-var ReportSquare = require('../../models').ReportSquare;
-var ReportDial = require('../../models').ReportDial;
+var models = require('../../models');
function Cleaner(ami) {
console.log('Cleaner Initialization...');
- removeInactiveCalls(ami);
+ var channels = ['Chat', 'Mail', 'Fax', 'Sms', 'Openchannel'];
+ clean(ami, channels);
setInterval(function() {
- removeInactiveCalls(ami);
+ clean(ami, channels);
}, 10 * 60 * 1000);
}
+function clean(ami, channels) {
+ removeInactiveCalls(ami);
+ _.forEach(channels, function(channel) {
+ removeExpiredApplications(channel);
+ });
+}
+
function removeInactiveCalls(ami) {
console.log('Removing inactive calls...');
var _bulkClean = [],
}
});
}
- return ReportQueue
+ return models.ReportQueue
.findAll({
where: {
$or: [{
}))
}
});
- return ReportSquare
+ return models.ReportSquare
.findAll({
where: {
leaveAt: null
}
});
- return ReportDial
+ return models.ReportDial
.findAll({
where: {
endtime: null
});
}
+function removeExpiredApplications(channel) {
+
+ return models['Report' + channel + 'Session']
+ .findAll({
+ where: {
+ leaveAt: null,
+ timeslot: { //If for any reason the timeslot is not populated I can't check if the app is expired
+ $ne: null
+ }
+ }
+ })
+ .then(function(sessions) {
+ var expiration, bulkFix = [];
+ _.forEach(sessions, function(session) {
+ expiration = moment(session.updatedAt).add(session.timeslot, 'seconds');
+ if (moment().isSameOrAfter(expiration)) {
+ bulkFix.push(session.updateAttributes({
+ leaveAt: moment().format("YYYY-MM-DD HH:mm:ss")
+ }));
+ }
+ });
+
+ return bulkFix;
+ })
+ .all()
+ .then(function() {
+ console.log('Inactive ' + channel + ' sessions cleaning completed!:');
+ })
+ .catch(function(err) {
+ console.log('Inactive ' + channel + ' sessions remove error:', err);
+ });
+
+}
+
module.exports = Cleaner;
--- /dev/null
+'use strict';
+
+module.exports = {
+ up: function(queryInterface, Sequelize) {
+ queryInterface.addColumn('report_chat_session_history', 'timeslot', Sequelize.INTEGER);
+ queryInterface.addColumn('report_mail_session_history', 'timeslot', Sequelize.INTEGER);
+ queryInterface.addColumn('report_fax_session_history', 'timeslot', Sequelize.INTEGER);
+ queryInterface.addColumn('report_sms_session_history', 'timeslot', Sequelize.INTEGER);
+ queryInterface.addColumn('report_openchannel_session_history', 'timeslot', Sequelize.INTEGER);
+ },
+
+ down: function(queryInterface, Sequelize) {
+ queryInterface.removeColumn('report_chat_session_history', 'timeslot');
+ queryInterface.removeColumn('report_mail_session_history', 'timeslot');
+ queryInterface.removeColumn('report_fax_session_history', 'timeslot');
+ queryInterface.removeColumn('report_sms_session_history', 'timeslot');
+ queryInterface.removeColumn('report_openchannel_session_history', 'timeslot');
+ }
+};
--- /dev/null
+'use strict';
+
+module.exports = {
+ up: function(queryInterface, Sequelize) {
+ queryInterface.addColumn('report_chat_session', 'timeslot', Sequelize.INTEGER);
+ queryInterface.addColumn('report_mail_session', 'timeslot', Sequelize.INTEGER);
+ queryInterface.addColumn('report_fax_session', 'timeslot', Sequelize.INTEGER);
+ queryInterface.addColumn('report_sms_session', 'timeslot', Sequelize.INTEGER);
+ queryInterface.addColumn('report_openchannel_session', 'timeslot', Sequelize.INTEGER);
+ },
+
+ down: function(queryInterface, Sequelize) {
+ queryInterface.removeColumn('report_chat_session', 'timeslot');
+ queryInterface.removeColumn('report_mail_session', 'timeslot');
+ queryInterface.removeColumn('report_fax_session', 'timeslot');
+ queryInterface.removeColumn('report_sms_session', 'timeslot');
+ queryInterface.removeColumn('report_openchannel_session', 'timeslot');
+ }
+};
timeout: {
type: DataTypes.BOOLEAN,
defaultValue: 0
- }
+ },
+ timeslot: DataTypes.INTEGER
}, {
tableName: 'report_chat_session_history'
});
timeout: {
type: DataTypes.BOOLEAN,
defaultValue: false
- }
+ },
+ timeslot: DataTypes.INTEGER
}, {
tableName: 'report_fax_session_history'
});
timeout: {
type: DataTypes.BOOLEAN,
defaultValue: false
- }
+ },
+ timeslot: DataTypes.INTEGER
}, {
tableName: 'report_mail_session_history'
});
timeout: {
type: DataTypes.BOOLEAN,
defaultValue: false
- }
+ },
+ timeslot: DataTypes.INTEGER
}, {
tableName: 'report_openchannel_session_history'
});
timeout: {
type: DataTypes.BOOLEAN,
defaultValue: false
- }
+ },
+ timeslot: DataTypes.INTEGER
}, {
tableName: 'report_sms_session_history'
});
timeout: {
type: DataTypes.BOOLEAN,
defaultValue: 0
- }
+ },
+ timeslot: DataTypes.INTEGER
}, {
tableName: 'report_chat_session'
});
timeout: {
type: DataTypes.BOOLEAN,
defaultValue: false
- }
+ },
+ timeslot: DataTypes.INTEGER
}, {
tableName: 'report_fax_session'
});
timeout: {
type: DataTypes.BOOLEAN,
defaultValue: false
- }
+ },
+ timeslot: DataTypes.INTEGER
}, {
tableName: 'report_mail_session'
});
timeout: {
type: DataTypes.BOOLEAN,
defaultValue: false
- }
+ },
+ timeslot: DataTypes.INTEGER
}, {
tableName: 'report_openchannel_session'
});
timeout: {
type: DataTypes.BOOLEAN,
defaultValue: false
- }
+ },
+ timeslot: DataTypes.INTEGER
}, {
tableName: 'report_sms_session'
});