Finaliazação do monitoramento da sessão

pull/1/head
adriano 2022-06-28 22:27:17 -03:00
parent 7fd739f812
commit bb04db9708
4 changed files with 102 additions and 26 deletions

View File

@ -11,7 +11,7 @@ import { convertBytes } from "./ConvertBytes";
const fastFolderSize = require('fast-folder-size')
const { promisify } = require('util')
const fs = require('fs')
let scheduler_monitor: any;
let timeInterval = 5
@ -53,31 +53,48 @@ const monitor = async () => {
}
// WHATS SESSION SIZE MONITORING
const whatsapps = await ListWhatsAppsService();
whatsapps.forEach(async whats => {
console.log('whats id: ', whats.id)
// console.log('whats id: ', whats.id)
const sourcePath = path.join(__dirname, `../../.wwebjs_auth/`, `session-bd_${whats.id}`)
const fastFolderSizeAsync = promisify(fastFolderSize)
if (fs.existsSync(sourcePath)) {
let size = await fastFolderSizeAsync(sourcePath)
try {
// console.log('dir path exist!')
const fastFolderSizeAsync = promisify(fastFolderSize)
size = convertBytes(size)
let size = await fastFolderSizeAsync(sourcePath)
console.log(size)
size = convertBytes(size)
// SESSION MONITORING
// const io = getIO();
// io.emit("whatsappSessionMonit", {
// action: "update",
// whatsappSessionSize: {
// id: whats.id,
// sessionSize: size
// }
// });
// console.log(size)
// SESSION MONITORING
const io = getIO();
io.emit("whatsappSessionMonit", {
action: "update",
whatsappSessionSize: {
id: whats.id,
sessionSize: size
}
});
}
catch (err) {
console.log('An error occurred while get info from the directory: ', err);
}
}
else {
console.log('Directory not found to get size info: ', sourcePath)
}
});

View File

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

View File

@ -38,6 +38,19 @@ const reducer = (state, action) => {
}
}
if (action.type === "UPDATE_WHATSAPPS_SESSION_MONIT") {
const whatsApp = action.payload;
const whatsAppIndex = state.findIndex(s => s.id === whatsApp.id);
if (whatsAppIndex !== -1) {
state[whatsAppIndex].sessionSize = whatsApp.sessionSize;
return [...state];
} else {
return [whatsApp, ...state];
}
}
if (action.type === "DELETE_WHATSAPPS") {
const whatsAppId = action.payload;
@ -48,6 +61,7 @@ const reducer = (state, action) => {
return [...state];
}
if (action.type === "RESET") {
return [];
}
@ -89,10 +103,26 @@ const useWhatsApps = () => {
socket.on("whatsappSession", data => {
if (data.action === "update") {
dispatch({ type: "UPDATE_SESSION", payload: data.session });
}
});
//test del
socket.on("whatsappSessionMonit", data => {
if (data.action === "update") {
console.log('data.whatsappSessionSize: ', data.whatsappSessionSize)
dispatch({ type: "UPDATE_WHATSAPPS_SESSION_MONIT", payload: data.whatsappSessionSize });
}
});
//
return () => {
socket.disconnect();
};

View File

@ -359,7 +359,7 @@ const Connections = () => {
<MainHeaderButtonsWrapper>
<Can
role={user.profile}
perform="btn-add-whatsapp"
perform="btn-add-whatsapp" updatedAt
yes={() => (
<Button
variant="contained"
@ -404,7 +404,19 @@ const Connections = () => {
perform="connection-button:show"
yes={() => (
<TableCell align="center">
Restart
Restore
</TableCell>
)}
/>
<Can
role={user.profile}
perform="connection-button:show"
yes={() => (
<TableCell align="center">
Session MB
</TableCell>
)}
/>
@ -465,7 +477,7 @@ const Connections = () => {
onClick={() => handleRestartWhatsAppSession(whatsApp.id)}
>
Restart
Restore
</Button>
</TableCell>
@ -474,6 +486,23 @@ const Connections = () => {
<Can
role={user.profile}
perform="connection-button:show"
yes={() => (
<TableCell align="center">
<CustomToolTip
title={'Informação da sessão em Megabytes'}
content={'Tamanho do diretorio da sessão atualizado a cada 5 segundos'}
>
<div>{whatsApp.sessionSize}</div>
</CustomToolTip>
</TableCell>
)}
/>
<TableCell align="center">