feat: Backup & Restore - Manual backup tested complete.
This commit is contained in:
@@ -7,6 +7,15 @@ import cron from 'node-cron';
|
||||
import { logger } from '../logging/logger';
|
||||
import { processScheduledNotifications } from '../../features/notifications/jobs/notification-processor.job';
|
||||
import { processAccountPurges } from '../../features/user-profile/jobs/account-purge.job';
|
||||
import {
|
||||
processScheduledBackups,
|
||||
setBackupJobPool,
|
||||
} from '../../features/backup/jobs/backup-scheduled.job';
|
||||
import {
|
||||
processBackupRetention,
|
||||
setBackupCleanupJobPool,
|
||||
} from '../../features/backup/jobs/backup-cleanup.job';
|
||||
import { pool } from '../config/database';
|
||||
|
||||
let schedulerInitialized = false;
|
||||
|
||||
@@ -18,6 +27,10 @@ export function initializeScheduler(): void {
|
||||
|
||||
logger.info('Initializing cron scheduler');
|
||||
|
||||
// Initialize backup job pools
|
||||
setBackupJobPool(pool);
|
||||
setBackupCleanupJobPool(pool);
|
||||
|
||||
// Daily notification processing at 8 AM
|
||||
cron.schedule('0 8 * * *', async () => {
|
||||
logger.info('Running scheduled notification job');
|
||||
@@ -47,8 +60,38 @@ export function initializeScheduler(): void {
|
||||
}
|
||||
});
|
||||
|
||||
// Check for scheduled backups every minute
|
||||
cron.schedule('* * * * *', async () => {
|
||||
logger.debug('Checking for scheduled backups');
|
||||
try {
|
||||
await processScheduledBackups();
|
||||
} catch (error) {
|
||||
logger.error('Scheduled backup check failed', {
|
||||
error: error instanceof Error ? error.message : String(error)
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Backup retention cleanup at 4 AM daily (after backups complete)
|
||||
cron.schedule('0 4 * * *', async () => {
|
||||
logger.info('Running backup retention cleanup job');
|
||||
try {
|
||||
const result = await processBackupRetention();
|
||||
logger.info('Backup retention cleanup completed', {
|
||||
processed: result.processed,
|
||||
totalDeleted: result.totalDeleted,
|
||||
totalFreedBytes: result.totalFreedBytes,
|
||||
errors: result.errors.length,
|
||||
});
|
||||
} catch (error) {
|
||||
logger.error('Backup retention cleanup failed', {
|
||||
error: error instanceof Error ? error.message : String(error)
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
schedulerInitialized = true;
|
||||
logger.info('Cron scheduler initialized - notification job (8 AM) and account purge job (2 AM) scheduled daily');
|
||||
logger.info('Cron scheduler initialized - notification (8 AM), account purge (2 AM), backup check (every min), retention cleanup (4 AM)');
|
||||
}
|
||||
|
||||
export function isSchedulerInitialized(): boolean {
|
||||
|
||||
Reference in New Issue
Block a user