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