b6b345f245
- Refactor email verification and password reset utilities to use new email service. - Introduce email delivery queue and notification delivery model for better tracking. - Enhance file validation and storage services for improved security and ownership management. - Add cron job for cleaning inactive notifications with retention policy. - Update document worker to handle document generation and storage more efficiently. - Implement logging improvements in activity and log workers. - Create comprehensive documentation for new API endpoints and services. - Add unit tests for file validation and notification policies to ensure robustness.
74 lines
1.6 KiB
JavaScript
74 lines
1.6 KiB
JavaScript
/**
|
|
* Copyright (c) 2026 Niolla
|
|
* All rights reserved.
|
|
*
|
|
* This source code is proprietary and confidential.
|
|
* Unauthorized copying, modification, distribution, or use
|
|
* of this file, via any medium, is strictly prohibited.
|
|
*/
|
|
|
|
// app/workers/log.worker.js
|
|
|
|
const { Worker } = require("bullmq");
|
|
const fs = require("fs");
|
|
const path = require("path");
|
|
|
|
const connection = require("../config/redisClient");
|
|
|
|
const logsDirectory = path.join(__dirname, "../../logs");
|
|
|
|
// Ensure logs directory exists
|
|
fs.mkdirSync(logsDirectory, { recursive: true });
|
|
|
|
const createLogWorker = () => {
|
|
const worker = new Worker(
|
|
"logQueue",
|
|
|
|
async (job) => {
|
|
const { message, timestamp, level = "info", service = "zumri-api", requestId, metadata } = job.data;
|
|
|
|
const logDate = new Date(timestamp)
|
|
.toISOString()
|
|
.split("T")[0];
|
|
|
|
const logFilePath = path.join(
|
|
logsDirectory,
|
|
`app-${logDate}.log`
|
|
);
|
|
|
|
const logLine = `${JSON.stringify({ timestamp, level, service, requestId, message, metadata })}\n`;
|
|
|
|
await fs.promises.appendFile(
|
|
logFilePath,
|
|
logLine,
|
|
"utf8"
|
|
);
|
|
},
|
|
|
|
{
|
|
connection,
|
|
}
|
|
);
|
|
|
|
worker.on("completed", (job) => {
|
|
console.log(`Log job ${job.id} completed`);
|
|
});
|
|
|
|
worker.on("failed", (job, err) => {
|
|
console.error(
|
|
`Log job ${job?.id} failed:`,
|
|
err
|
|
);
|
|
});
|
|
|
|
worker.on("error", (err) => {
|
|
console.error("Log worker error:", err);
|
|
});
|
|
|
|
console.log("🟢 Log worker started");
|
|
|
|
return worker;
|
|
};
|
|
|
|
module.exports = createLogWorker;
|