UNPKG

@waboyz-baileys/jobs

Version:

24 lines (23 loc) 947 B
import cron from 'node-cron'; export function startGlobalMessageArchiver(getStorages, logger, daysOld) { cron.schedule('0 3 * * *', async () => { const storages = getStorages(); logger.info(`[CRON] Starting batch message archiving (older than ${daysOld} days)...`); for (const clientId in storages) { const storage = storages.get(clientId); if (!storage) continue; try { const archive = storage.messageArchive; const count = await archive?.archiveOldMessages(daysOld); logger.info(`[CRON] [${clientId}] Archived ${count} messages.`); } catch (err) { logger.error(`[CRON] [${clientId}] Failed to archive messages: ${err}`); } } }, { timezone: 'Europe/Istanbul' }); logger.info(`[CRON] Global message archiver scheduled at 03:00 daily.`); }