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 fastFolderSize = require('fast-folder-size')
const { promisify } = require('util') const { promisify } = require('util')
const fs = require('fs')
let scheduler_monitor: any; let scheduler_monitor: any;
let timeInterval = 5 let timeInterval = 5
@ -53,31 +53,48 @@ const monitor = async () => {
} }
// WHATS SESSION SIZE MONITORING
const whatsapps = await ListWhatsAppsService(); const whatsapps = await ListWhatsAppsService();
whatsapps.forEach(async whats => { 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 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 // console.log(size)
// const io = getIO();
// io.emit("whatsappSessionMonit", { // SESSION MONITORING
// action: "update", const io = getIO();
// whatsappSessionSize: { io.emit("whatsappSessionMonit", {
// id: whats.id, action: "update",
// sessionSize: size 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); gracefulShutdown(server);
startSchedulingMonitor(5000) 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") { if (action.type === "DELETE_WHATSAPPS") {
const whatsAppId = action.payload; const whatsAppId = action.payload;
@ -48,6 +61,7 @@ const reducer = (state, action) => {
return [...state]; return [...state];
} }
if (action.type === "RESET") { if (action.type === "RESET") {
return []; return [];
} }
@ -89,10 +103,26 @@ const useWhatsApps = () => {
socket.on("whatsappSession", data => { socket.on("whatsappSession", data => {
if (data.action === "update") { if (data.action === "update") {
dispatch({ type: "UPDATE_SESSION", payload: data.session }); 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 () => { return () => {
socket.disconnect(); socket.disconnect();
}; };

View File

@ -359,7 +359,7 @@ const Connections = () => {
<MainHeaderButtonsWrapper> <MainHeaderButtonsWrapper>
<Can <Can
role={user.profile} role={user.profile}
perform="btn-add-whatsapp" perform="btn-add-whatsapp" updatedAt
yes={() => ( yes={() => (
<Button <Button
variant="contained" variant="contained"
@ -404,7 +404,19 @@ const Connections = () => {
perform="connection-button:show" perform="connection-button:show"
yes={() => ( yes={() => (
<TableCell align="center"> <TableCell align="center">
Restart Restore
</TableCell>
)}
/>
<Can
role={user.profile}
perform="connection-button:show"
yes={() => (
<TableCell align="center">
Session MB
</TableCell> </TableCell>
)} )}
/> />
@ -465,7 +477,7 @@ const Connections = () => {
onClick={() => handleRestartWhatsAppSession(whatsApp.id)} onClick={() => handleRestartWhatsAppSession(whatsApp.id)}
> >
Restart Restore
</Button> </Button>
</TableCell> </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"> <TableCell align="center">