Criação do monitoramento da sessão

pull/1/head
adriano 2022-06-28 21:34:43 -03:00
parent c5c13f2b34
commit 7fd739f812
6 changed files with 110 additions and 49 deletions

View File

@ -25,6 +25,7 @@
"dotenv": "^8.2.0",
"express": "^4.17.1",
"express-async-errors": "^3.1.1",
"fast-folder-size": "^1.7.0",
"fs-extra": "^10.1.0",
"http-graceful-shutdown": "^2.3.2",
"jsonwebtoken": "^8.5.1",

View File

@ -15,6 +15,7 @@ import AppError from "../errors/AppError";
import path from 'path';
interface WhatsappData {
name: string;
queueIds: number[];

View File

@ -0,0 +1,23 @@
const fsPromises = require("fs/promises");
const fs = require('fs-extra')
// Delete a directory and its children
export const convertBytes = (bytes: number,) => {
const sizes = ["Bytes", "KB", "MB", "GB", "TB"]
if (bytes == 0) {
return "n/a"
}
const i = +(Math.floor(Math.log(bytes) / Math.log(1024)))
if (i == 0) {
return bytes + " " + sizes[i]
}
// return (bytes / Math.pow(1024, i)).toFixed(1) + " " + sizes[i]
return (bytes / Math.pow(1024, i)).toFixed(1)
}

View File

@ -4,7 +4,13 @@ import SendWhatsAppMessage from "../services/WbotServices/SendWhatsAppMessage";
import ListSchedulingNotifyService from "../services/SchedulingNotifyServices/ListSchedulingNotifyService";
import DeleteSchedulingNotifyService from "../services/SchedulingNotifyServices/DeleteSchedulingNotifyService";
import { getIO } from "../libs/socket";
import ListWhatsAppsService from "../services/WhatsappService/ListWhatsAppsService";
import path from "path";
import { convertBytes } from "./ConvertBytes";
const fastFolderSize = require('fast-folder-size')
const { promisify } = require('util')
let scheduler_monitor: any;
@ -46,6 +52,37 @@ const monitor = async () => {
}
const whatsapps = await ListWhatsAppsService();
whatsapps.forEach(async whats => {
console.log('whats id: ', whats.id)
const sourcePath = path.join(__dirname, `../../.wwebjs_auth/`, `session-bd_${whats.id}`)
const fastFolderSizeAsync = promisify(fastFolderSize)
let size = await fastFolderSizeAsync(sourcePath)
size = convertBytes(size)
console.log(size)
// SESSION MONITORING
// const io = getIO();
// io.emit("whatsappSessionMonit", {
// action: "update",
// whatsappSessionSize: {
// id: whats.id,
// sessionSize: size
// }
// });
});
} catch (error) {
console.log('>>> SchedulingNotifiySendMessage.ts error: ', error)
stopSchedulingMonitor()
@ -73,4 +110,3 @@ export const stopSchedulingMonitor =async ( ) => {

View File

@ -157,7 +157,7 @@ const monitor = async () => {
if (countTest == 0) {
try {
// console.log(' Carregando usuárion no listUserId...')
console.log(' Carregando usuárion no listUserId...')
listUserId = await ListUserParamiterService({ profile: 'user' })
} catch (error) {

View File

@ -16,4 +16,4 @@ StartAllWhatsAppsSessions();
gracefulShutdown(server);
startSchedulingMonitor(5000)
startWhoIsOnlineMonitor(2000)
startWhoIsOnlineMonitor(4000)