2022-01-06 01:26:15 +00:00
|
|
|
import gracefulShutdown from "http-graceful-shutdown";
|
|
|
|
import app from "./app";
|
2023-02-07 15:47:40 +00:00
|
|
|
import { initIO, getIO } from "./libs/socket";
|
2022-01-06 01:26:15 +00:00
|
|
|
import { logger } from "./utils/logger";
|
|
|
|
import { StartAllWhatsAppsSessions } from "./services/WbotServices/StartAllWhatsAppsSessions";
|
2023-02-07 15:47:40 +00:00
|
|
|
import User from "./models/User";
|
2022-10-25 14:16:36 +00:00
|
|
|
|
2022-01-06 01:26:15 +00:00
|
|
|
const server = app.listen(process.env.PORT, () => {
|
|
|
|
logger.info(`Server started on port: ${process.env.PORT}`);
|
|
|
|
});
|
|
|
|
|
2022-12-31 06:12:26 +00:00
|
|
|
|
2023-02-07 15:47:40 +00:00
|
|
|
if (global.gc) {
|
2023-01-07 19:35:25 +00:00
|
|
|
console.log(">> Starting Garbage Collector...");
|
2023-02-07 15:47:40 +00:00
|
|
|
global.gc();
|
2023-01-07 19:35:25 +00:00
|
|
|
} else {
|
|
|
|
console.warn('No GC hook! Start your program as `node --expose-gc file.js`.');
|
2023-02-07 15:47:40 +00:00
|
|
|
}
|
|
|
|
|
2022-01-06 01:26:15 +00:00
|
|
|
initIO(server);
|
2023-02-07 15:47:40 +00:00
|
|
|
|
2023-01-25 20:44:02 +00:00
|
|
|
// StartAllWhatsAppsSessions();
|
2022-01-06 01:26:15 +00:00
|
|
|
gracefulShutdown(server);
|
2023-02-07 15:47:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
setTimeout(async () => {
|
|
|
|
|
|
|
|
const io = getIO();
|
|
|
|
|
|
|
|
console.log('Triggered socket!')
|
|
|
|
|
|
|
|
let users = await User.findAll({ raw: true, attributes: ["id"], })
|
|
|
|
|
|
|
|
|
|
|
|
if (users && users.length > 0) {
|
|
|
|
for (let i = 0; i < users.length; i++) {
|
|
|
|
|
|
|
|
io.emit("reload_page", {
|
|
|
|
action: "update",
|
|
|
|
userId: users[i].id
|
|
|
|
});
|
|
|
|
|
|
|
|
console.log('USER ID: ', users[i].id)
|
|
|
|
|
|
|
|
await new Promise(f => setTimeout(f, 500));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}, 5000)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|