Merge branch 'create-database-connections-pool' into 'master'
Create database connections pool See merge request saburly/psihologija!28
This commit was merged in pull request #28.
This commit is contained in:
@@ -1,3 +1,9 @@
|
|||||||
|
const pool = {
|
||||||
|
max: parseInt(process.env.DB_POOL_MAX_CONNECTIONS) || 5,
|
||||||
|
acquire: parseInt(process.env.DB_POOL_ACQUIRE) || 60000,
|
||||||
|
evict: parseInt(process.env.DB_POOL_EVICT) || 1000,
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
development: {
|
development: {
|
||||||
username: 'docker',
|
username: 'docker',
|
||||||
@@ -5,14 +11,17 @@ module.exports = {
|
|||||||
database: 'CrmIntegration',
|
database: 'CrmIntegration',
|
||||||
port: '5431',
|
port: '5431',
|
||||||
dialect: 'postgres',
|
dialect: 'postgres',
|
||||||
logging: parseInt(process.env.SEQUELIZE_LOGGING) ? console.log : false
|
logging: parseInt(process.env.SEQUELIZE_LOGGING) ? console.log : false,
|
||||||
|
pool
|
||||||
},
|
},
|
||||||
test: {
|
test: {
|
||||||
"use_env_variable": 'DATABASE_URL',
|
"use_env_variable": 'DATABASE_URL',
|
||||||
logging: parseInt(process.env.SEQUELIZE_LOGGING) ? console.log : false
|
logging: parseInt(process.env.SEQUELIZE_LOGGING) ? console.log : false,
|
||||||
|
pool
|
||||||
},
|
},
|
||||||
production: {
|
production: {
|
||||||
"use_env_variable": 'DATABASE_URL',
|
"use_env_variable": 'DATABASE_URL',
|
||||||
logging: parseInt(process.env.SEQUELIZE_LOGGING) ? console.log : false
|
logging: parseInt(process.env.SEQUELIZE_LOGGING) ? console.log : false,
|
||||||
|
pool
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ const officeRnDAPIErrors = {
|
|||||||
FAILED_TO_ADD_FEES: 'Failed to add fees in ORD',
|
FAILED_TO_ADD_FEES: 'Failed to add fees in ORD',
|
||||||
};
|
};
|
||||||
const integrationServiceErrors = {
|
const integrationServiceErrors = {
|
||||||
|
IMPORT_SUCCESSFUL_CALCULATION_FAILED: 'Import succeeded but fetching reservations and calculating charges failed',
|
||||||
FAILED_TO_SAVE_BOOKINGS: 'Failed to save booking reservations',
|
FAILED_TO_SAVE_BOOKINGS: 'Failed to save booking reservations',
|
||||||
FAILED_TO_SAVE_DOOR_LOCK_ENTRIES: 'Failed to save door lock entries',
|
FAILED_TO_SAVE_DOOR_LOCK_ENTRIES: 'Failed to save door lock entries',
|
||||||
FAILED_TO_SAVE_DATA_GENERIC: 'Failed to save data',
|
FAILED_TO_SAVE_DATA_GENERIC: 'Failed to save data',
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ const { parseDoorLockDataFile, writeDoorLockEvent } = require('../services/doorL
|
|||||||
const { fetchAllBookings, writeBookingReservation } = require('../services/officeRnD/bookings');
|
const { fetchAllBookings, writeBookingReservation } = require('../services/officeRnD/bookings');
|
||||||
const { calculateDoorLockCharges } = require('../services/integration/doorLockCharges');
|
const { calculateDoorLockCharges } = require('../services/integration/doorLockCharges');
|
||||||
const { integrationServiceErrors } = require('../constants/constants');
|
const { integrationServiceErrors } = require('../constants/constants');
|
||||||
|
const { checkBookingChanges } = require('../services/integration/checkBookingChange');
|
||||||
|
|
||||||
const IncomingForm = require('formidable').IncomingForm;
|
const IncomingForm = require('formidable').IncomingForm;
|
||||||
|
|
||||||
@@ -42,11 +43,25 @@ const uploadDoorLockData = (req, res) => {
|
|||||||
|
|
||||||
Promise.all(asyncWriteJobs)
|
Promise.all(asyncWriteJobs)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
res.json({
|
checkBookingChanges()
|
||||||
parsedData,
|
.then(() => {
|
||||||
parserErrors,
|
calculateDoorLockCharges()
|
||||||
unknownMembers
|
.then(() => {
|
||||||
});
|
res.json({
|
||||||
|
parsedData,
|
||||||
|
parserErrors,
|
||||||
|
unknownMembers
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.log('Error : ', error);
|
||||||
|
res.status(500).send(integrationServiceErrors.IMPORT_SUCCESSFUL_CALCULATION_FAILED);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.log('Error : ', error);
|
||||||
|
res.status(500).send(integrationServiceErrors.IMPORT_SUCCESSFUL_CALCULATION_FAILED);
|
||||||
|
});
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.log(integrationServiceErrors.FAILED_TO_SAVE_DOOR_LOCK_ENTRIES);
|
console.log(integrationServiceErrors.FAILED_TO_SAVE_DOOR_LOCK_ENTRIES);
|
||||||
@@ -54,7 +69,7 @@ const uploadDoorLockData = (req, res) => {
|
|||||||
res.status(500).send(integrationServiceErrors.FAILED_TO_SAVE_DATA_GENERIC);
|
res.status(500).send(integrationServiceErrors.FAILED_TO_SAVE_DATA_GENERIC);
|
||||||
});
|
});
|
||||||
|
|
||||||
fetchAllBookings()
|
/*fetchAllBookings()
|
||||||
.then((bookingEntries) => {
|
.then((bookingEntries) => {
|
||||||
const asyncJobs = [];
|
const asyncJobs = [];
|
||||||
bookingEntries.forEach((bookingEntry) => asyncJobs.push(writeBookingReservation(bookingEntry)));
|
bookingEntries.forEach((bookingEntry) => asyncJobs.push(writeBookingReservation(bookingEntry)));
|
||||||
@@ -62,13 +77,18 @@ const uploadDoorLockData = (req, res) => {
|
|||||||
Promise.all(asyncJobs)
|
Promise.all(asyncJobs)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
calculateDoorLockCharges();
|
calculateDoorLockCharges();
|
||||||
});
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.log('Error updating booking reservations : ');
|
||||||
|
console.log(error);
|
||||||
|
})
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.log(integrationServiceErrors.FAILED_TO_SAVE_BOOKINGS);
|
console.log(integrationServiceErrors.FAILED_TO_SAVE_BOOKINGS);
|
||||||
console.log(error);
|
console.log(error);
|
||||||
return;
|
return;
|
||||||
});
|
});
|
||||||
|
*/
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
res.status(500).send(error);
|
res.status(500).send(error);
|
||||||
|
|||||||
@@ -24,3 +24,8 @@ BOOKING_CHANGE_PERCENTAGE_CHARGE=Percentage of hourly reate to apply for cancell
|
|||||||
ALLOWED_BOOKING_CANCELLATION_TIME=Time from creation (in minutes) in which cancellation is not charged
|
ALLOWED_BOOKING_CANCELLATION_TIME=Time from creation (in minutes) in which cancellation is not charged
|
||||||
|
|
||||||
SEQUELIZE_LOGGING=0 - false, 1 - true (console logging)
|
SEQUELIZE_LOGGING=0 - false, 1 - true (console logging)
|
||||||
|
|
||||||
|
#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)
|
||||||
|
DB_POOL_EVICT=The time interval, in milliseconds, after which sequelize-pool will remove idle connections. (ex. 10000)
|
||||||
|
|||||||
@@ -510,52 +510,66 @@ const getIncidentData = (reservation) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const calculateDoorLockCharges = () => {
|
const calculateDoorLockCharges = () => {
|
||||||
getAllFinishedBookings()
|
return new Promise((resolve, reject) => {
|
||||||
.then((reservations) => {
|
getAllFinishedBookings()
|
||||||
const unlockedIncidents = [];
|
.then((reservations) => {
|
||||||
const unscheduledIncidents = [];
|
const unlockedIncidents = [];
|
||||||
|
const unscheduledIncidents = [];
|
||||||
|
|
||||||
const asyncCheckForIncidents = [];
|
const asyncCheckForIncidents = [];
|
||||||
|
|
||||||
reservations.forEach((reservation) => {
|
reservations.forEach((reservation) => {
|
||||||
asyncCheckForIncidents.push(getIncidentData(reservation));
|
asyncCheckForIncidents.push(getIncidentData(reservation));
|
||||||
});
|
});
|
||||||
|
|
||||||
Promise.all(asyncCheckForIncidents)
|
Promise.all(asyncCheckForIncidents)
|
||||||
.then((allReservationsIncidents) => {
|
.then((allReservationsIncidents) => {
|
||||||
allReservationsIncidents.forEach((reservationIncidents) => {
|
allReservationsIncidents.forEach((reservationIncidents) => {
|
||||||
reservationIncidents.forEach((incident) => {
|
reservationIncidents.forEach((incident) => {
|
||||||
if (incident.error) {
|
if (incident.error) {
|
||||||
console.log('Error checking incident : ', incident.error);
|
console.log('Error checking incident : ', incident.error);
|
||||||
} else if (incident.incidentType) {
|
} else if (incident.incidentType) {
|
||||||
switch (incident.incidentType) {
|
switch (incident.incidentType) {
|
||||||
case incidentType.UNLOCKED_INCIDENT_RELATED_WITH_RESERVATION:
|
case incidentType.UNLOCKED_INCIDENT_RELATED_WITH_RESERVATION:
|
||||||
case incidentType.UNLOCKED_INCIDENT_STANDALONE:
|
case incidentType.UNLOCKED_INCIDENT_STANDALONE:
|
||||||
unlockedIncidents.push(incident);
|
unlockedIncidents.push(incident);
|
||||||
break;
|
break;
|
||||||
case incidentType.UNSCHEDULED_INCIDENT_BEFORE_RESERVATION:
|
case incidentType.UNSCHEDULED_INCIDENT_BEFORE_RESERVATION:
|
||||||
case incidentType.UNSCHEDULED_INCIDENT_AFTER_RESERVATION:
|
case incidentType.UNSCHEDULED_INCIDENT_AFTER_RESERVATION:
|
||||||
case incidentType.UNSCHEDULED_INCIDENT_STANDALONE:
|
case incidentType.UNSCHEDULED_INCIDENT_STANDALONE:
|
||||||
unscheduledIncidents.push(incident);
|
unscheduledIncidents.push(incident);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
insertUnscheduledIncidents(unscheduledIncidents)
|
setUnlockedIncidentsLevel(unlockedIncidents)
|
||||||
.catch((error) => console.log(error));
|
.then((completedUnlockedIncidents) => {
|
||||||
|
const insertIncidentsJobs = [insertUnscheduledIncidents(unscheduledIncidents), insertUnlockedIncidents(completedUnlockedIncidents)];
|
||||||
|
|
||||||
setUnlockedIncidentsLevel(unlockedIncidents)
|
Promise.all(insertIncidentsJobs)
|
||||||
.then((completedUnlockedIncidents) => {
|
.then(() => {
|
||||||
insertUnlockedIncidents(completedUnlockedIncidents)
|
resolve(true);
|
||||||
.catch((error) => console.log(error));
|
})
|
||||||
})
|
.catch((error) => {
|
||||||
.catch((error) => console.log(error));
|
reject(error);
|
||||||
})
|
});
|
||||||
.catch((error) => console.log(error));
|
|
||||||
})
|
/*
|
||||||
.catch((error) => console.log(error));
|
insertUnscheduledIncidents(unscheduledIncidents)
|
||||||
|
.catch((error) => console.log(error));
|
||||||
|
|
||||||
|
insertUnlockedIncidents(completedUnlockedIncidents)
|
||||||
|
.catch((error) => console.log(error));
|
||||||
|
*/
|
||||||
|
})
|
||||||
|
.catch((error) => reject(error));
|
||||||
|
})
|
||||||
|
.catch((error) => reject(error));
|
||||||
|
})
|
||||||
|
.catch((error) => reject(error));
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|||||||
Reference in New Issue
Block a user