projeto-hit/backend/src/server.ts

48 lines
1.3 KiB
TypeScript
Raw Normal View History

import gracefulShutdown from "http-graceful-shutdown";
import app from "./app";
import { initIO } from "./libs/socket";
import { logger } from "./utils/logger";
import { StartAllWhatsAppsSessions } from "./services/WbotServices/StartAllWhatsAppsSessions";
import "./helpers/SchedulingNotifySendMessage"
import { startWhoIsOnlineMonitor } from "./helpers/WhoIsOnlineMonitor"
import { loadTicketsCache, flushCache, cacheSize } from './helpers/TicketCache'
import { loadContactsCache } from './helpers/ContactsCache'
2022-11-17 14:40:37 +00:00
import { loadWhatsappCache } from './helpers/WhatsCache'
2022-12-14 12:29:42 +00:00
import { delRestoreControllFile } from "./helpers/RestoreControll";
import { createSessionDir } from "./helpers/CreateSessionDir";
import { loadSchedulesCache, } from "./helpers/SchedulingNotifyCache";
const server = app.listen(process.env.PORT, () => {
logger.info(`Server started on port: ${process.env.PORT}`);
});
initIO(server);
StartAllWhatsAppsSessions();
gracefulShutdown(server);
(async()=>{
const cacheLength = await cacheSize()
console.log('cacheSize: ', cacheLength)
if(cacheLength == 0){
console.log('Loading from cache...')
await flushCache()
await loadContactsCache()
await loadTicketsCache()
2022-11-17 14:40:37 +00:00
await loadWhatsappCache()
await loadSchedulesCache()
}
2022-12-14 12:29:42 +00:00
})()
2022-12-14 12:29:42 +00:00
createSessionDir()
delRestoreControllFile()
startWhoIsOnlineMonitor(3000)