Merged in feature/IO-2921-CARSTAR-Canada-Chatter-Integration (pull request #1944)
IO-2921 Chatter Datapump Adjustment
This commit is contained in:
@@ -17,17 +17,15 @@ const ftpSetup = {
|
||||
port: process.env.CHATTER_PORT,
|
||||
username: process.env.CHATTER_USER,
|
||||
privateKey: null,
|
||||
debug: process.env.NODE_ENV !== "production"
|
||||
? (message, ...data) => logger.log(message, "DEBUG", "api", null, data)
|
||||
: () => {},
|
||||
debug:
|
||||
process.env.NODE_ENV !== "production"
|
||||
? (message, ...data) => logger.log(message, "DEBUG", "api", null, data)
|
||||
: () => {},
|
||||
algorithms: {
|
||||
serverHostKey: ["ssh-rsa", "ssh-dss", "rsa-sha2-256", "rsa-sha2-512", "ecdsa-sha2-nistp256", "ecdsa-sha2-nistp384"]
|
||||
}
|
||||
};
|
||||
|
||||
const allChatterObjects = [];
|
||||
const allErrors = [];
|
||||
|
||||
exports.default = async (req, res) => {
|
||||
// Only process if in production environment.
|
||||
if (process.env.NODE_ENV !== "production") {
|
||||
@@ -49,12 +47,13 @@ exports.default = async (req, res) => {
|
||||
|
||||
try {
|
||||
logger.log("chatter-start", "DEBUG", "api", null, null);
|
||||
const allChatterObjects = [];
|
||||
const allErrors = [];
|
||||
|
||||
const { bodyshops } = await client.request(queries.GET_CHATTER_SHOPS); //Query for the List of Bodyshop Clients.
|
||||
const specificShopIds = req.body.bodyshopIds; // ['uuid];
|
||||
const { start, end, skipUpload } = req.body; //YYYY-MM-DD
|
||||
|
||||
const batchSize = 10;
|
||||
|
||||
const shopsToProcess =
|
||||
specificShopIds?.length > 0 ? bodyshops.filter((shop) => specificShopIds.includes(shop.id)) : bodyshops;
|
||||
logger.log("chatter-shopsToProcess-generated", "DEBUG", "api", null, null);
|
||||
@@ -64,16 +63,14 @@ exports.default = async (req, res) => {
|
||||
return;
|
||||
}
|
||||
|
||||
for (let i = 0; i < shopsToProcess.length; i += batchSize) {
|
||||
const batch = shopsToProcess.slice(i, i + batchSize);
|
||||
await processBatch(batch, start, end);
|
||||
}
|
||||
await processBatch(shopsToProcess, start, end, allChatterObjects, allErrors);
|
||||
|
||||
const csvToUpload = {
|
||||
count: allChatterObjects.length,
|
||||
csv: converter.json2csv(allChatterObjects, { emptyFieldValue: "" }),
|
||||
filename: `IMEX_ONLINE_solicitation_${moment().format("YYYYMMDD")}.csv`
|
||||
};
|
||||
|
||||
if (skipUpload) {
|
||||
await fs.promises.writeFile(`./logs/${csvToUpload.filename}`, csvToUpload.csv);
|
||||
} else {
|
||||
@@ -92,8 +89,8 @@ exports.default = async (req, res) => {
|
||||
}
|
||||
};
|
||||
|
||||
async function processBatch(batch, start, end) {
|
||||
for (const bodyshop of batch) {
|
||||
async function processBatch(shopsToProcess, start, end, allChatterObjects, allErrors) {
|
||||
for (const bodyshop of shopsToProcess) {
|
||||
try {
|
||||
logger.log("chatter-start-shop-extract", "DEBUG", "api", bodyshop.id, {
|
||||
shopname: bodyshop.shopname
|
||||
|
||||
Reference in New Issue
Block a user