change runtimeCheckLog
This commit is contained in:
parent
c6333d40ea
commit
6d04a73c35
|
|
@ -87,13 +87,14 @@ export async function runtimeCheckLogs(folderPath) {
|
|||
// Watch for changes in the files listed
|
||||
async function watchFilesInList() {
|
||||
//only check new file ---> fileList - fileList_old = new file
|
||||
let listFileWatch = fileList.slice(0, 40)?.filter((i) => fileList_old.includes(i) === false).map((file) => folderPath + "/" + file)
|
||||
const watcher = chokidar.watch(
|
||||
fileList.slice(0,40)
|
||||
?.filter((i) => fileList_old.includes(i) === false)
|
||||
.map((file) => folderPath + "/" + file),{
|
||||
listFileWatch,
|
||||
{
|
||||
persistent: true,
|
||||
interval: 300000
|
||||
});
|
||||
interval: 300000,
|
||||
}
|
||||
);
|
||||
|
||||
watcher.setMaxListeners(200);
|
||||
|
||||
|
|
@ -101,16 +102,20 @@ export async function runtimeCheckLogs(folderPath) {
|
|||
// fs.watchFile(filePath,{ interval: 15000 },
|
||||
// async (eventType) => {
|
||||
//check special item, extra RAM, error in log
|
||||
const fileName = path.split("/")[path.split("/").length - 1]
|
||||
const filePath = path
|
||||
const fileName = path.split("/")[path.split("/").length - 1];
|
||||
const filePath = path;
|
||||
let lines = [];
|
||||
const today = DateTime.now().toFormat('yyyy-MM-dd');
|
||||
let allFile = await LogDetectFile.query()
|
||||
.whereRaw(`DATE(created_at) = ?`, [today])
|
||||
const today = DateTime.now().toFormat("yyyy-MM-dd");
|
||||
let allFile = await LogDetectFile.query().whereRaw(
|
||||
`DATE(created_at) = ?`,
|
||||
[today]
|
||||
);
|
||||
// let allReport = await LogReport.all();
|
||||
let allValue = await KeyValue.all();
|
||||
const allReport = await LogReport.query()
|
||||
.whereRaw(`DATE(created_at) = ?`, [today])
|
||||
const allReport = await LogReport.query().whereRaw(
|
||||
`DATE(created_at) = ?`,
|
||||
[today]
|
||||
);
|
||||
|
||||
//get information file
|
||||
let fileDetect = allFile?.filter(
|
||||
|
|
@ -151,7 +156,7 @@ export async function runtimeCheckLogs(folderPath) {
|
|||
.map((obj) => obj.$original.value);
|
||||
|
||||
//Process file content
|
||||
if(contentFile.length>50000){
|
||||
if (contentFile.length > 50000) {
|
||||
for (let i = 0; i < contentFile.length; i += 1000) {
|
||||
const chunk = contentFile.slice(i, i + 1000);
|
||||
|
||||
|
|
@ -190,7 +195,7 @@ export async function runtimeCheckLogs(folderPath) {
|
|||
});
|
||||
});
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
contentFile.map((line, index) => {
|
||||
//check line the line with errors and exclude errors
|
||||
listKeyValues
|
||||
|
|
@ -198,8 +203,8 @@ export async function runtimeCheckLogs(folderPath) {
|
|||
.map(async (value) => {
|
||||
if (
|
||||
line.search(value) !== -1 &&
|
||||
listExcludeErr.filter((err) => line.includes(err))
|
||||
.length === 0
|
||||
listExcludeErr.filter((err) => line.includes(err)).length ===
|
||||
0
|
||||
) {
|
||||
let log = allFile?.filter(
|
||||
(i) => i.$original.file_name === fileName
|
||||
|
|
@ -230,13 +235,21 @@ 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("+contentFile.length+") ---Good");
|
||||
console.log(
|
||||
fileName + "has changed(" + contentFile.length + ") ---Good"
|
||||
);
|
||||
} else {
|
||||
console.log(
|
||||
fileName + "has changed("+contentFile.length+") ---SOS---"+lines.length
|
||||
fileName +
|
||||
"has changed(" +
|
||||
contentFile.length +
|
||||
") ---SOS---" +
|
||||
lines.length
|
||||
);
|
||||
let allReport_new = await LogReport.query().whereRaw(
|
||||
`DATE(created_at) = ?`,
|
||||
[today]
|
||||
);
|
||||
let allReport_new = await LogReport.query()
|
||||
.whereRaw(`DATE(created_at) = ?`, [today])
|
||||
|
||||
let fileDetect = allFile?.filter(
|
||||
(i) => i.$original.file_name === fileName
|
||||
|
|
@ -315,9 +328,13 @@ export async function runtimeCheckLogs(folderPath) {
|
|||
issueFound
|
||||
);
|
||||
}
|
||||
}, 3000)
|
||||
}, 3000);
|
||||
// console.log(path + " change")
|
||||
});
|
||||
|
||||
watcher.on("error", (error) => {
|
||||
console.error(`Watcher error: ${error}`);
|
||||
});
|
||||
// await fileList.slice(0,40)
|
||||
// ?.filter((i) => fileList_old.includes(i) === false)
|
||||
// ?.forEach((fileName) => {
|
||||
|
|
|
|||
Loading…
Reference in New Issue