1 Commits

Author SHA1 Message Date
Bilal Catic
bc56ed3f03 [NOT FINISHED] delete fees in chunks 2019-10-04 18:52:41 +02:00
3 changed files with 35 additions and 6 deletions

View File

@@ -135,7 +135,10 @@ const CUSTOM_FEES_PREFIXES = process.env.CUSTOM_FEES_PREFIXES.split(',')
const UNPAID_FEE_STATUS = 'not_paid';
const ALLOW_SENDING_FEES = parseInt(process.env.ALLOW_SENDING_FEES_FOR_CURRENT_AND_FUTURE_MONTHS) ? true : false;
const ALLOW_SENDING_FEES = !!parseInt(process.env.ALLOW_SENDING_FEES_FOR_CURRENT_AND_FUTURE_MONTHS);
const MAX_FEES_TO_DELETE = parseInt(process.env.MAX_FEES_TO_DELETE) || 10;
const FEES_DELETE_DELAY = parseInt(process.env.FEES_DELETE_DELAY) || 0;
module.exports = {
VALID_CSV_HEADERS,
@@ -162,4 +165,6 @@ module.exports = {
UNPAID_FEE_STATUS,
CUSTOM_FEES_PREFIXES,
ALLOW_SENDING_FEES,
MAX_FEES_TO_DELETE,
FEES_DELETE_DELAY
};

View File

@@ -41,6 +41,9 @@ CUSTOM_FEES_PREFIXES=Array of prefixes to recognize manually added fees. Comma-s
ALLOW_SENDING_FEES_FOR_CURRENT_AND_FUTURE_MONTHS=0 - false => Sending fees is disabled for current and future months, 1 - true => Sending fees is never disabled
MAX_FEES_TO_DELETE=Max number of fees to delete (from ORD) in one API call
FEES_DELETE_DELAY=Number of miliseconds to wait between two API calls to delete fees (from ORD)
#More about pool option : http://docs.sequelizejs.com/class/lib/sequelize.js~Sequelize.html
DB_POOL_MAX_CONNECTIONS=Maximum number of connection in pool (ex. 18)
DB_POOL_ACQUIRE=The maximum time, in milliseconds, that pool will try to get connection before throwing error (ex. 120000)

View File

@@ -3,7 +3,14 @@
const moment = require('moment-timezone');
const { API } = require('../../helpers/api');
const { officeRnDAPIErrors, DEFAULT_DATE_FORMAT, UNPAID_FEE_STATUS, CUSTOM_FEES_PREFIXES } = require('../../constants/constants');
const {
officeRnDAPIErrors,
DEFAULT_DATE_FORMAT,
UNPAID_FEE_STATUS,
CUSTOM_FEES_PREFIXES,
MAX_FEES_TO_DELETE,
FEES_DELETE_DELAY,
} = require('../../constants/constants');
const deleteFeesFromORD = (dateRange, memberIds) => {
return new Promise((resolve, reject) => {
@@ -63,14 +70,28 @@ const deleteFeesFromORD = (dateRange, memberIds) => {
}
});
API.delete('fees', { data: feeIdsToRemove })
const asyncDeleteCalls = [];
let i,j;
for (i=0, j=feeIdsToRemove; i<j; i+= MAX_FEES_TO_DELETE){
const feesSubset = feeIdsToRemove.slice(i, i+MAX_FEES_TO_DELETE);
const deleteFeesPromise = API.delete('fees', { data: feesSubset }).then(() => resolve(true)).catch((error) => {
console.log('[Delete Fees From ORD] Error deleting fees from ORD : ', error);
reject(officeRnDAPIErrors.FAILED_TO_DELETE_FEES);
});
asyncDeleteCalls.push(deleteFeesPromise);
//sleep for FEES_DELETE_DELAY ms
}
Promise.all(asyncDeleteCalls)
.then(() => {
resolve(feesToSkip);
})
.catch((error) => {
console.log('[Delete Fees From ORD] Error deleting fees from ORD : ', error);
reject(officeRnDAPIErrors.FAILED_TO_DELETE_FEES);
});
reject(error);
})
})
.catch((error) => {
console.log("[Delete Fees From ORD] Error fetching fees and plans from ORD : ", error);