change runtimeCheckLog

This commit is contained in:
joseph le 2023-10-04 09:25:01 +07:00
parent 42845467ef
commit 8ff674f50b
2 changed files with 83 additions and 84 deletions

View File

@ -1,5 +1,3 @@
import LogReport from "App/Models/LogReport";
export async function getListLineByItem(listReport) {
try {
// Mảng ban đầu

View File

@ -189,93 +189,94 @@ export async function runtimeCheckLogs(folderPath) {
});
//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.query()
.whereRaw(`DATE(created_at) = ?`, [today])
let fileDetect = allFile?.filter(
(i) => i.$original.file_name === fileName
)[0];
// 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.query()
// .whereRaw(`DATE(created_at) = ?`, [today])
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 fileDetect = allFile?.filter(
// (i) => i.$original.file_name === fileName
// )[0];
let content =
"| |Last updated at | Item/error | Line | Report \n|---|:---:|:---|:---|:-----------:\n";
let spoiler = "";
let issueFound = "";
// 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)
// );
listReport.map((log, index) => {
let item = listExtraItem.includes(log.detected_content)
? ":medal: **" + log.detected_content + "**"
: ":small_orange_diamond: " + log.detected_content;
// let content =
// "| |Last updated at | Item/error | Line | Report \n|---|:---:|:---|:---|:-----------:\n";
// let spoiler = "";
// let issueFound = "";
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";
});
// listReport.map((log, index) => {
// let item = listExtraItem.includes(log.detected_content)
// ? ":medal: **" + log.detected_content + "**"
// : ":small_orange_diamond: " + log.detected_content;
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);
// 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);