This commit is contained in:
Nuranggi Hermawan
2022-12-07 13:52:11 +07:00
parent 1c77488368
commit 0fe2a469da
+142 -71
View File
@@ -58,82 +58,153 @@ app.use("/api/", cashinRoute);
// ============================== SAP SCHEDULLER =============================
if (process.env.NODE_ENV.toUpperCase() == "PRODUCTION") {
// if (process.env.NODE_ENV.toUpperCase() == "PRODUCTION") {
// ===================================================
// SCHEDULER FOR GENERATE INVOICE
// const {
// _generateInvoice,
// _postingInvoice,
// } = require("../application/modules/invoiceonline/invoice.controller");
// ===================================================
// every 10 minutes
// cron.schedule('*/10 * * * *', async () => {
// every at 01:00
const {
_generateInvoice,
_postingInvoice,
} = require("../application/modules/invoiceonline/invoice.controller");
// GENERATE + POSTING INVOICE
// cron.schedule("0 1 * * *", async () => {
// try {
// // let ivoiceDate = moment().add(1, 'days').format("YYYY-MM-DD");
// let ivoiceDate = moment().format("YYYY-MM-DD");
// let uniqueCode = helper.getUniqueCode();
// winston.logger.debug(
// `STARTING SCHEDULER-FB70 GENERATE INVOICE ${ivoiceDate} `
// );
// const generate = await _generateInvoice(ivoiceDate, uniqueCode, false);
// winston.logger.debug(
// `END SCHEDULER-FB70 GENERATE INVOICE ${ivoiceDate} : ${JSON.stringify(
// generate
// )}`
// );
// const reGenerate = await _generateInvoice(ivoiceDate, uniqueCode, true);
// winston.logger.debug(
// `END SCHEDULER-FB70 RE-GENERATE INVOICE THAT HAVE BEEN DELETED ${ivoiceDate} : ${JSON.stringify(
// generate
// )}`
// );
// } catch (error) {
// // create log
// winston.logger.error(
// `500 internal server error - backend server | ${error.message}`
// );
// }
// });
cron.schedule("0 14 * * *", async () => {
try {
// let ivoiceDate = moment().add(1, 'days').format("YYYY-MM-DD");
let ivoiceDate = moment().format("YYYY-MM-DD");
let uniqueCode = helper.getUniqueCode();
winston.logger.debug(
`STARTING SCHEDULER-FB70 GENERATE INVOICE ${ivoiceDate} `
);
const generate = await _generateInvoice(ivoiceDate, uniqueCode, false);
winston.logger.debug(
`END SCHEDULER-FB70 GENERATE INVOICE ${ivoiceDate} : ${JSON.stringify(
generate
)}`
);
const reGenerate = await _generateInvoice(ivoiceDate, uniqueCode, true);
winston.logger.debug(
`END SCHEDULER-FB70 RE-GENERATE INVOICE THAT HAVE BEEN DELETED ${ivoiceDate} : ${JSON.stringify(
generate
)}`
);
} catch (error) {
// create log
winston.logger.error(
`500 internal server error - backend server | ${error.message}`
);
}
});
// every 15 minutes
// cron.schedule('*/15 * * * *', async () => {
// every 2 hour
// cron.schedule("0 */2 * * *", async () => {
// try {
// let uniqueCode = helper.getUniqueCode();
// winston.logger.debug(`STARTING SCHEDULER-FB70 POSTING INVOICE`);
// const posting = await _postingInvoice(uniqueCode);
// winston.logger.debug(
// `END SCHEDULER-FB70 POSTING INVOICE : ${JSON.stringify(posting)}`
// );
// } catch (error) {
// // create log
// winston.logger.error(
// `500 internal server error - backend server | ${error.message}`
// );
// }
// });
}
// RE-TRY POSTING
cron.schedule("0 7 * * *", async () => {
try {
let uniqueCode = helper.getUniqueCode();
winston.logger.debug(`STARTING SCHEDULER-FB70 RE-TRY POSTING INVOICE`);
const posting = await _postingInvoice(uniqueCode);
winston.logger.debug(
`END SCHEDULER-FB70 RE-TRY POSTING INVOICE : ${JSON.stringify(posting)}`
);
} catch (error) {
// create log
winston.logger.error(
`500 internal server error - backend server | ${error.message}`
);
}
});
cron.schedule("0 12 * * *", async () => {
try {
let uniqueCode = helper.getUniqueCode();
winston.logger.debug(`STARTING SCHEDULER-FB70 RE-TRY POSTING INVOICE`);
const posting = await _postingInvoice(uniqueCode);
winston.logger.debug(
`END SCHEDULER-FB70 RE-TRY POSTING INVOICE : ${JSON.stringify(posting)}`
);
} catch (error) {
// create log
winston.logger.error(
`500 internal server error - backend server | ${error.message}`
);
}
});
cron.schedule("0 17 * * *", async () => {
try {
let uniqueCode = helper.getUniqueCode();
winston.logger.debug(`STARTING SCHEDULER-FB70 RE-TRY POSTING INVOICE`);
const posting = await _postingInvoice(uniqueCode);
winston.logger.debug(
`END SCHEDULER-FB70 RE-TRY POSTING INVOICE : ${JSON.stringify(posting)}`
);
} catch (error) {
// create log
winston.logger.error(
`500 internal server error - backend server | ${error.message}`
);
}
});
// ===================================================
// SCHEDULER FOR GENERATE INVOICE
// ===================================================
// cash in
// const {
// _generateCashIn,
// } = require("../application/modules/cashin/cahsin.controller");
const {
_generateCashIn,
} = require("../application/modules/cashin/cahsin.controller");
// cron.schedule('* * * * *', async () => {
// try {
// let uniqueCode = helper.getUniqueCode();
// winston.logger.info(`STARTING SCHEDULER-FB70 GENERATE CASH IN ${uniqueCode}`);
// const posting = await _generateCashIn(uniqueCode);
// winston.logger.info(
// `END SCHEDULER-FB70 GENERATE CASH IN : ${JSON.stringify(posting)}`
// );
// } catch (error) {
// // create log
// winston.logger.error(
// `500 internal server error - backend server | ${error.message}`
// );
// }
// });
cron.schedule('30 7 * * *', async () => {
try {
let uniqueCode = helper.getUniqueCode();
winston.logger.info(`STARTING SCHEDULER-FB70 GENERATE CASH IN ${uniqueCode}`);
const posting = await _generateCashIn(uniqueCode);
winston.logger.info(
`END SCHEDULER-FB70 GENERATE CASH IN : ${JSON.stringify(posting)}`
);
} catch (error) {
// create log
winston.logger.error(
`500 internal server error - backend server | ${error.message}`
);
}
});
cron.schedule('30 12 * * *', async () => {
try {
let uniqueCode = helper.getUniqueCode();
winston.logger.info(`STARTING SCHEDULER-FB70 GENERATE CASH IN ${uniqueCode}`);
const posting = await _generateCashIn(uniqueCode);
winston.logger.info(
`END SCHEDULER-FB70 GENERATE CASH IN : ${JSON.stringify(posting)}`
);
} catch (error) {
// create log
winston.logger.error(
`500 internal server error - backend server | ${error.message}`
);
}
});
cron.schedule('30 17 * * *', async () => {
try {
let uniqueCode = helper.getUniqueCode();
winston.logger.info(`STARTING SCHEDULER-FB70 GENERATE CASH IN ${uniqueCode}`);
const posting = await _generateCashIn(uniqueCode);
winston.logger.info(
`END SCHEDULER-FB70 GENERATE CASH IN : ${JSON.stringify(posting)}`
);
} catch (error) {
// create log
winston.logger.error(
`500 internal server error - backend server | ${error.message}`
);
}
});
// }
module.exports = app;