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