change runtimeCheckLog
This commit is contained in:
parent
1e255cf6d7
commit
ec3fbfc857
|
|
@ -106,167 +106,178 @@ export async function runtimeCheckLogs(folderPath) {
|
||||||
let allReport = await LogReport.all();
|
let allReport = await LogReport.all();
|
||||||
let allValue = await KeyValue.all();
|
let allValue = await KeyValue.all();
|
||||||
|
|
||||||
//get information file
|
|
||||||
let fileDetect = allFile?.filter(
|
|
||||||
(i) => i.$original.file_name === fileName
|
|
||||||
)[0];
|
|
||||||
|
|
||||||
let logsDetect = allReport?.filter(
|
console.log(allReport)
|
||||||
(i) => i.$original.id_file === fileDetect?.id_ldf
|
|
||||||
);
|
|
||||||
//get the last line detected
|
|
||||||
let lastLine = Math.max(...logsDetect.map((obj) => obj.line));
|
|
||||||
|
|
||||||
//get content file in local
|
|
||||||
let contentFile = await fs
|
|
||||||
.readFileSync(filePath)
|
|
||||||
.toString()
|
|
||||||
?.split("\n");
|
|
||||||
|
|
||||||
//get index SN and send to ERP
|
|
||||||
|
|
||||||
checkIndexSN(contentFile, lastLine, fileName);
|
|
||||||
|
|
||||||
//get list item to check
|
// //get information file
|
||||||
let listKeyValues = allValue.filter(
|
// let fileDetect = allFile?.filter(
|
||||||
(i) =>
|
// (i) => i.$original.file_name === fileName
|
||||||
i.$original.key === "MODEL_SPECIAL" ||
|
// )[0];
|
||||||
i.$original.key === "CATCH_FAULTY"
|
|
||||||
);
|
|
||||||
|
|
||||||
//get list exclude error
|
// let logsDetect = allReport?.filter(
|
||||||
let listExcludeErr = allValue
|
// (i) => i.$original.id_file === fileDetect?.id_ldf
|
||||||
.filter((i) => i.$original.key === "EXCLUDE_ERR")
|
// );
|
||||||
.map((obj) => obj.$original.value);
|
// //get the last line detected
|
||||||
|
// let lastLine = Math.max(...logsDetect.map((obj) => obj.line));
|
||||||
|
|
||||||
//get list item special
|
// //get content file in local
|
||||||
let listExtraItem = allValue
|
// let contentFile = await fs
|
||||||
.filter((i) => i.$original.key === "MODEL_SPECIAL")
|
// .readFileSync(filePath)
|
||||||
.map((obj) => obj.$original.value);
|
// .toString()
|
||||||
|
// ?.split("\n");
|
||||||
|
|
||||||
//Process file content
|
// //get index SN and send to ERP
|
||||||
contentFile.map((line, index) => {
|
|
||||||
//check line the line with errors and exclude errors
|
|
||||||
listKeyValues
|
|
||||||
.map((obj) => obj.$original.value)
|
|
||||||
.map(async (value) => {
|
|
||||||
if (
|
|
||||||
line.search(value) !== -1 &&
|
|
||||||
listExcludeErr.filter((err) => line.includes(err))
|
|
||||||
.length === 0
|
|
||||||
) {
|
|
||||||
let log = allFile?.filter(
|
|
||||||
(i) => i.$original.file_name === fileName
|
|
||||||
)[0];
|
|
||||||
|
|
||||||
let checkLog = allReport?.filter(
|
// checkIndexSN(contentFile, lastLine, fileName);
|
||||||
(report) =>
|
|
||||||
report.$original.id_file === log?.id_ldf &&
|
|
||||||
report.$original.line === index + 1 &&
|
|
||||||
report.$original.detected_content === value
|
|
||||||
);
|
|
||||||
|
|
||||||
if (checkLog?.length === 0) {
|
// //get list item to check
|
||||||
await LogReport.create({
|
// let listKeyValues = allValue.filter(
|
||||||
detected_content: value,
|
// (i) =>
|
||||||
line: index + 1,
|
// i.$original.key === "MODEL_SPECIAL" ||
|
||||||
id_file: log?.id_ldf,
|
// i.$original.key === "CATCH_FAULTY"
|
||||||
});
|
// );
|
||||||
lines.push(index + 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// if(checkSpecialVersion())
|
// //get list exclude error
|
||||||
});
|
// let listExcludeErr = allValue
|
||||||
});
|
// .filter((i) => i.$original.key === "EXCLUDE_ERR")
|
||||||
|
// .map((obj) => obj.$original.value);
|
||||||
|
|
||||||
//true: import log to log_report table, send report to Zulip
|
// //get list item special
|
||||||
setTimeout(async () => {
|
// let listExtraItem = allValue
|
||||||
if (lines.length === 0) {
|
// .filter((i) => i.$original.key === "MODEL_SPECIAL")
|
||||||
console.log(`${fileName} has changed ---Good`);
|
// .map((obj) => obj.$original.value);
|
||||||
} else {
|
|
||||||
console.log(
|
// //Process file content
|
||||||
`${fileName} has changed ---SOS---${lines.length}`
|
// contentFile.map((line, index) => {
|
||||||
);
|
// //check line the line with errors and exclude errors
|
||||||
let allReport_new = await LogReport.all();
|
// listKeyValues
|
||||||
let fileDetect = allFile?.filter(
|
// .map((obj) => obj.$original.value)
|
||||||
(i) => i.$original.file_name === fileName
|
// .map(async (value) => {
|
||||||
)[0];
|
// if (
|
||||||
|
// line.search(value) !== -1 &&
|
||||||
|
// listExcludeErr.filter((err) => line.includes(err))
|
||||||
|
// .length === 0
|
||||||
|
// ) {
|
||||||
|
// let log = allFile?.filter(
|
||||||
|
// (i) => i.$original.file_name === fileName
|
||||||
|
// )[0];
|
||||||
|
|
||||||
|
// let checkLog = allReport?.filter(
|
||||||
|
// (report) =>
|
||||||
|
// report.$original.id_file === log?.id_ldf &&
|
||||||
|
// report.$original.line === index + 1 &&
|
||||||
|
// report.$original.detected_content === value
|
||||||
|
// );
|
||||||
|
|
||||||
|
// if (checkLog?.length === 0) {
|
||||||
|
// await LogReport.create({
|
||||||
|
// detected_content: value,
|
||||||
|
// line: index + 1,
|
||||||
|
// id_file: log?.id_ldf,
|
||||||
|
// });
|
||||||
|
// lines.push(index + 1);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // if(checkSpecialVersion())
|
||||||
|
// });
|
||||||
|
// });
|
||||||
|
|
||||||
|
// //true: import log to log_report table, send report to Zulip
|
||||||
|
// setTimeout(async () => {
|
||||||
|
// if (lines.length === 0) {
|
||||||
|
// console.log(`${fileName} has changed ---Good`);
|
||||||
|
// } else {
|
||||||
|
// console.log(
|
||||||
|
// `${fileName} has changed ---SOS---${lines.length}`
|
||||||
|
// );
|
||||||
|
// let allReport_new = await LogReport.all();
|
||||||
|
// let fileDetect = allFile?.filter(
|
||||||
|
// (i) => i.$original.file_name === fileName
|
||||||
|
// )[0];
|
||||||
|
|
||||||
|
// let logsDetect = allReport_new?.filter(
|
||||||
|
// (i) => i.$original.id_file === fileDetect?.id_ldf
|
||||||
|
// );
|
||||||
|
// // console.log(logsDetect)
|
||||||
|
// // await Database.rawQuery(
|
||||||
|
// // "select * from log_reports where id_file = " +
|
||||||
|
// // fileDetect?.id_ldf
|
||||||
|
// // );
|
||||||
|
// //Get all report newest
|
||||||
|
// let listReport = await getListLineByItem(
|
||||||
|
// logsDetect
|
||||||
|
// .map((obj) => obj.$original)
|
||||||
|
// .filter((l) => l.line > lastLine)
|
||||||
|
// );
|
||||||
|
|
||||||
|
// let content =
|
||||||
|
// "| |Last updated at | Item/error | Line | Report \n|---|:---:|:---|:---|:-----------:\n";
|
||||||
|
// let spoiler = "";
|
||||||
|
// let issueFound = "";
|
||||||
|
|
||||||
|
// listReport.map((log, index) => {
|
||||||
|
// let item = listExtraItem.includes(log.detected_content)
|
||||||
|
// ? ":medal: **" + log.detected_content + "**"
|
||||||
|
// : ":small_orange_diamond: " + log.detected_content;
|
||||||
|
|
||||||
|
// log.line?.map((line) => {
|
||||||
|
// issueFound =
|
||||||
|
// issueFound +
|
||||||
|
// "\n`" +
|
||||||
|
// line +
|
||||||
|
// "` " +
|
||||||
|
// contentFile[line - 1]?.replace(
|
||||||
|
// log.detected_content,
|
||||||
|
// "[" +
|
||||||
|
// log.detected_content +
|
||||||
|
// "](https://logs.danielvu.com/logs/" +
|
||||||
|
// fileName +
|
||||||
|
// "#" +
|
||||||
|
// line +
|
||||||
|
// ")"
|
||||||
|
// );
|
||||||
|
// });
|
||||||
|
// content =
|
||||||
|
// content +
|
||||||
|
// "|" +
|
||||||
|
// (index + 1) +
|
||||||
|
// "|**" +
|
||||||
|
// moment(Date.now()).format("HH:mm - DD/MM") +
|
||||||
|
// "**|" +
|
||||||
|
// item +
|
||||||
|
// "|" +
|
||||||
|
// log.line +
|
||||||
|
// "|[View](https://logs.danielvu.com/logs/" +
|
||||||
|
// fileName +
|
||||||
|
// "#" +
|
||||||
|
// log.line +
|
||||||
|
// ")\n";
|
||||||
|
// });
|
||||||
|
|
||||||
|
// sendMessToZulip(
|
||||||
|
// "stream",
|
||||||
|
// Env.get("ZULIP_STREAM_ALERT"),
|
||||||
|
// Env.get("ZULIP_TOPIC_ALERT"),
|
||||||
|
// "------------\n\n:warning: :warning: **" +
|
||||||
|
// fileName +
|
||||||
|
// "**\n\n" +
|
||||||
|
// content +
|
||||||
|
// "\n\n" +
|
||||||
|
// spoiler +
|
||||||
|
// "\n\n***Issue found:***\n" +
|
||||||
|
// issueFound
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
// }, 3000);
|
||||||
|
|
||||||
let logsDetect = allReport_new?.filter(
|
|
||||||
(i) => i.$original.id_file === fileDetect?.id_ldf
|
|
||||||
);
|
|
||||||
// console.log(logsDetect)
|
|
||||||
// await Database.rawQuery(
|
|
||||||
// "select * from log_reports where id_file = " +
|
|
||||||
// fileDetect?.id_ldf
|
|
||||||
// );
|
|
||||||
//Get all report newest
|
|
||||||
let listReport = await getListLineByItem(
|
|
||||||
logsDetect
|
|
||||||
.map((obj) => obj.$original)
|
|
||||||
.filter((l) => l.line > lastLine)
|
|
||||||
);
|
|
||||||
|
|
||||||
let content =
|
|
||||||
"| |Last updated at | Item/error | Line | Report \n|---|:---:|:---|:---|:-----------:\n";
|
|
||||||
let spoiler = "";
|
|
||||||
let issueFound = "";
|
|
||||||
|
|
||||||
listReport.map((log, index) => {
|
|
||||||
let item = listExtraItem.includes(log.detected_content)
|
|
||||||
? ":medal: **" + log.detected_content + "**"
|
|
||||||
: ":small_orange_diamond: " + log.detected_content;
|
|
||||||
|
|
||||||
log.line?.map((line) => {
|
|
||||||
issueFound =
|
|
||||||
issueFound +
|
|
||||||
"\n`" +
|
|
||||||
line +
|
|
||||||
"` " +
|
|
||||||
contentFile[line - 1]?.replace(
|
|
||||||
log.detected_content,
|
|
||||||
"[" +
|
|
||||||
log.detected_content +
|
|
||||||
"](https://logs.danielvu.com/logs/" +
|
|
||||||
fileName +
|
|
||||||
"#" +
|
|
||||||
line +
|
|
||||||
")"
|
|
||||||
);
|
|
||||||
});
|
|
||||||
content =
|
|
||||||
content +
|
|
||||||
"|" +
|
|
||||||
(index + 1) +
|
|
||||||
"|**" +
|
|
||||||
moment(Date.now()).format("HH:mm - DD/MM") +
|
|
||||||
"**|" +
|
|
||||||
item +
|
|
||||||
"|" +
|
|
||||||
log.line +
|
|
||||||
"|[View](https://logs.danielvu.com/logs/" +
|
|
||||||
fileName +
|
|
||||||
"#" +
|
|
||||||
log.line +
|
|
||||||
")\n";
|
|
||||||
});
|
|
||||||
|
|
||||||
sendMessToZulip(
|
|
||||||
"stream",
|
|
||||||
Env.get("ZULIP_STREAM_ALERT"),
|
|
||||||
Env.get("ZULIP_TOPIC_ALERT"),
|
|
||||||
"------------\n\n:warning: :warning: **" +
|
|
||||||
fileName +
|
|
||||||
"**\n\n" +
|
|
||||||
content +
|
|
||||||
"\n\n" +
|
|
||||||
spoiler +
|
|
||||||
"\n\n***Issue found:***\n" +
|
|
||||||
issueFound
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}, 3000);
|
|
||||||
|
|
||||||
console.log(path + " change")
|
console.log(path + " change")
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue