rabbitMQ command

This commit is contained in:
AdisakKanthawilang 2024-10-11 11:05:31 +07:00
parent cb4fc6defb
commit 608c8967bc
7 changed files with 440 additions and 37 deletions

View file

@ -5,11 +5,14 @@ import express from "express";
import swaggerUi from "swagger-ui-express";
import swaggerDocument from "./swagger.json";
import * as cron from "node-cron";
import { init as rabbitmqInit } from './services/rabbitmq';
import error from "./middlewares/error";
import { AppDataSource } from "./database/data-source";
import { RegisterRoutes } from "./routes";
import { OrganizationController } from "./controllers/OrganizationController";
import logMiddleware from "./middlewares/logs";
import { run } from "node:test";
import { CommandController } from "./controllers/CommandController";
async function main() {
await AppDataSource.initialize();
@ -43,6 +46,17 @@ async function main() {
}
});
const cronTime_command = "0 2 * * * *";
// const cronTime_command = "*/10 * * * * *";
cron.schedule(cronTime_command, async () => {
try {
const commandController = new CommandController();
await commandController.cronjobCommand();
} catch (error) {
console.error("Error executing function from controller:", error);
}
});
// app.listen(APP_PORT, APP_HOST, () => console.log(`Listening on: http://localhost:${APP_PORT}`));
app.listen(
APP_PORT,
@ -52,6 +66,16 @@ async function main() {
console.log(`[APP] Swagger on: http://localhost:${APP_PORT}/api-docs`)
),
);
async function runMessageQueue() {
try {
await rabbitmqInit();
} catch (e) {
console.log(e);
setTimeout(runMessageQueue, 1000);
}
}
runMessageQueue()
}
main();