Initial commit: teaching institution management API.
Express/MongoDB backend with JWT auth, RBAC, S3 uploads, notifications, and scheduled jobs.
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
// /jobs/tempBucketCleanupJob.js
|
||||
|
||||
const cron = require('node-cron');
|
||||
const { cleanupTempBucket } = require('../utils/s3Client');
|
||||
const logger = require('../utils/logger');
|
||||
|
||||
const runTempBucketCleanupJob = async () => {
|
||||
try {
|
||||
logger.info('[TempBucketCleanupJob] Starting daily temp bucket cleanup...');
|
||||
const deletedCount = await cleanupTempBucket(10); // Files older than 10 minutes
|
||||
logger.info(`[TempBucketCleanupJob] Daily cleanup finished. Removed ${deletedCount} files.`);
|
||||
} catch (error) {
|
||||
logger.error(`[TempBucketCleanupJob ERROR]: ${error.message}`);
|
||||
}
|
||||
};
|
||||
|
||||
const startTempBucketCleanupJob = () => {
|
||||
// Schedule daily at 3:00 AM
|
||||
cron.schedule('0 3 * * *', async () => {
|
||||
await runTempBucketCleanupJob();
|
||||
});
|
||||
logger.info('[TempBucketCleanupJob] Scheduled to run daily at 3:00 AM.');
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
startTempBucketCleanupJob,
|
||||
runTempBucketCleanupJob
|
||||
};
|
||||
Reference in New Issue
Block a user