This commit is contained in:
2026-04-06 23:39:27 +05:00
parent 76ee4b7ac3
commit 73ace950fa
4 changed files with 235 additions and 9 deletions

View File

@@ -1,5 +1,6 @@
// cron-jobs.js
const { logActivity } = require('./database');
const { sendChatSummaryNotifications } = require('./notifications');
/**
* Проверяет задачи с типом document_approval, у которых указан номер документа,
@@ -87,6 +88,27 @@ function checkDocumentsForCompletion(db) {
});
}
/**
* Запускает cron-задачу для отправки сводок о новых сообщениях в чате.
* Отправка происходит раз в час.
*/
function startChatNotificationsCron() {
console.log('🕐 [CRON] Запущен планировщик уведомлений чата (каждый час)');
// Первый запуск через 5 секунд после старта сервера, затем каждый час
setTimeout(async () => {
console.log('📢 [CRON] Первый запуск отправки сводок чата...');
await sendChatSummaryNotifications();
// Запускаем интервал
setInterval(async () => {
console.log('📢 [CRON] Плановый запуск отправки сводок чата...');
await sendChatSummaryNotifications();
}, 60 * 60 * 1000); // 1 час
}, 5000); // 5 секунд
}
module.exports = {
checkDocumentsForCompletion
checkDocumentsForCompletion,
startChatNotificationsCron
};