43 lines
1.2 KiB
TypeScript
43 lines
1.2 KiB
TypeScript
import dotenv from "dotenv";
|
|
import logger, { logDone, logError, logIntent } from "./config/logger.js";
|
|
import mongoose from "mongoose";
|
|
import { JobProcessor } from "./Models/Jobs/JobProcessor.js";
|
|
|
|
logIntent("Iniciando Notification Sender.");
|
|
|
|
logIntent("Cargando variables de entorno.");
|
|
const envResult = dotenv.config();
|
|
|
|
if (envResult.error) {
|
|
logError("Error cargando variables de entorno:", envResult.error);
|
|
process.exit(1);
|
|
}
|
|
|
|
logDone("Variables de entorno cargadas correctamente.");
|
|
|
|
const MONGO_URI = process.env.DATABASE_CONNECTION;
|
|
|
|
if (!MONGO_URI) {
|
|
logError("DATABASE_CONNECTION no está definido en las variables de entorno.", "");
|
|
process.exit(1);
|
|
}
|
|
|
|
logIntent("Conectando a MongoDB.");
|
|
mongoose
|
|
.connect(MONGO_URI)
|
|
.then(() => {
|
|
const start = async () => {
|
|
logDone("Conexión a MongoDB establecida correctamente.");
|
|
logger.info("🚀 Notification Sender running (job-based polling)");
|
|
|
|
const processor = new JobProcessor();
|
|
await processor.startPolling();
|
|
};
|
|
|
|
start();
|
|
})
|
|
.catch((err) => {
|
|
logError("Error conectando a MongoDB:", err);
|
|
process.exit(1);
|
|
});
|