Criação do monitoramento da sessão
parent
c5c13f2b34
commit
7fd739f812
|
@ -25,6 +25,7 @@
|
||||||
"dotenv": "^8.2.0",
|
"dotenv": "^8.2.0",
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
"express-async-errors": "^3.1.1",
|
"express-async-errors": "^3.1.1",
|
||||||
|
"fast-folder-size": "^1.7.0",
|
||||||
"fs-extra": "^10.1.0",
|
"fs-extra": "^10.1.0",
|
||||||
"http-graceful-shutdown": "^2.3.2",
|
"http-graceful-shutdown": "^2.3.2",
|
||||||
"jsonwebtoken": "^8.5.1",
|
"jsonwebtoken": "^8.5.1",
|
||||||
|
|
|
@ -15,6 +15,7 @@ import AppError from "../errors/AppError";
|
||||||
|
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
|
|
||||||
interface WhatsappData {
|
interface WhatsappData {
|
||||||
name: string;
|
name: string;
|
||||||
queueIds: number[];
|
queueIds: number[];
|
||||||
|
|
|
@ -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)
|
||||||
|
|
||||||
|
}
|
|
@ -4,7 +4,13 @@ import SendWhatsAppMessage from "../services/WbotServices/SendWhatsAppMessage";
|
||||||
|
|
||||||
import ListSchedulingNotifyService from "../services/SchedulingNotifyServices/ListSchedulingNotifyService";
|
import ListSchedulingNotifyService from "../services/SchedulingNotifyServices/ListSchedulingNotifyService";
|
||||||
import DeleteSchedulingNotifyService from "../services/SchedulingNotifyServices/DeleteSchedulingNotifyService";
|
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;
|
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) {
|
} catch (error) {
|
||||||
console.log('>>> SchedulingNotifiySendMessage.ts error: ', error)
|
console.log('>>> SchedulingNotifiySendMessage.ts error: ', error)
|
||||||
stopSchedulingMonitor()
|
stopSchedulingMonitor()
|
||||||
|
@ -73,4 +110,3 @@ export const stopSchedulingMonitor =async ( ) => {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -157,7 +157,7 @@ const monitor = async () => {
|
||||||
|
|
||||||
if (countTest == 0) {
|
if (countTest == 0) {
|
||||||
try {
|
try {
|
||||||
// console.log(' Carregando usuárion no listUserId...')
|
console.log(' Carregando usuárion no listUserId...')
|
||||||
listUserId = await ListUserParamiterService({ profile: 'user' })
|
listUserId = await ListUserParamiterService({ profile: 'user' })
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
@ -16,4 +16,4 @@ StartAllWhatsAppsSessions();
|
||||||
gracefulShutdown(server);
|
gracefulShutdown(server);
|
||||||
|
|
||||||
startSchedulingMonitor(5000)
|
startSchedulingMonitor(5000)
|
||||||
startWhoIsOnlineMonitor(2000)
|
startWhoIsOnlineMonitor(4000)
|
||||||
|
|
Loading…
Reference in New Issue