From b309a43fe300767c525a3281207c6f8d21507d36 Mon Sep 17 00:00:00 2001 From: adriano Date: Fri, 10 Feb 2023 11:03:23 -0300 Subject: [PATCH] =?UTF-8?q?Habilita=C3=A7=C3=A3o=20do=20envio=20de=20infor?= =?UTF-8?q?ma=C3=A7=C3=A3o=20de=20espa=C3=A7o=20no=20servidor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../helpers/SchedulingNotifySendMessage.ts | 52 +++++++++---------- backend/src/server.ts | 28 +++++++++- 2 files changed, 53 insertions(+), 27 deletions(-) diff --git a/backend/src/helpers/SchedulingNotifySendMessage.ts b/backend/src/helpers/SchedulingNotifySendMessage.ts index c9d3d68..405cc13 100644 --- a/backend/src/helpers/SchedulingNotifySendMessage.ts +++ b/backend/src/helpers/SchedulingNotifySendMessage.ts @@ -102,47 +102,47 @@ const monitor = async () => { // WHATS SESSION SIZE MONITORING - const whatsapps = await ListWhatsAppsService(); + // const whatsapps = await ListWhatsAppsService(); - whatsapps.forEach(async whats => { + // whatsapps.forEach(async whats => { - const sourcePath = path.join(__dirname, `../../.wwebjs_auth/`, `session-bd_${whats.id}`) + // const sourcePath = path.join(__dirname, `../../.wwebjs_auth/`, `session-bd_${whats.id}`) - if (fs.existsSync(sourcePath)) { + // if (fs.existsSync(sourcePath)) { - try { + // try { - const fastFolderSizeAsync = promisify(fastFolderSize) + // const fastFolderSizeAsync = promisify(fastFolderSize) - let size = await fastFolderSizeAsync(sourcePath) + // let size = await fastFolderSizeAsync(sourcePath) - size = convertBytes(size) + // size = convertBytes(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); - } + // // 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 { + // } + // else { - // console.log('Directory not found to get size info: ', sourcePath) + // // console.log('Directory not found to get size info: ', sourcePath) - } + // } - }); + // }); diff --git a/backend/src/server.ts b/backend/src/server.ts index 7cc3c3f..e23571d 100644 --- a/backend/src/server.ts +++ b/backend/src/server.ts @@ -6,6 +6,13 @@ import { StartAllWhatsAppsSessions } from "./services/WbotServices/StartAllWhats import User from "./models/User"; import Whatsapp from "./models/Whatsapp"; import endPointQuery from "./helpers/EndPointQuery"; +import { cacheSize, flushCache, loadTicketsCache } from "./helpers/TicketCache"; +import { loadContactsCache } from "./helpers/ContactsCache"; +import { loadSchedulesCache } from "./helpers/SchedulingNotifyCache"; +import { delRestoreControllFile } from "./helpers/RestoreControll"; + +import "./helpers/SchedulingNotifySendMessage" + const server = app.listen(process.env.PORT, () => { logger.info(`Server started on port: ${process.env.PORT}`); @@ -44,7 +51,7 @@ gracefulShutdown(server); } } catch (error: any) { - + await whatsapps[i].update({ status: 'OPENING' }); console.log(`There was an error on try acess the api sessions ${whatsapps[i].dataValues.url}`) @@ -55,6 +62,25 @@ gracefulShutdown(server); } } + + if (process.env.CACHE) { + + const cacheLength = await cacheSize() + + console.log('cacheSize: ', cacheLength) + + if (cacheLength == 0) { + console.log('Loading from cache...') + await flushCache() + await loadContactsCache() + await loadTicketsCache() + } + + await loadSchedulesCache() + // await loadWhatsappCache() + } + + delRestoreControllFile() })() setTimeout(async () => {