-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
41 lines (37 loc) · 1.21 KB
/
index.js
File metadata and controls
41 lines (37 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
require('dotenv').config();
const schedule = require('node-schedule');
const prisma = require('./prismaClient');
/* // Every minute: delete any verifying records older than 10 minutes
schedule.scheduleJob('* * * * *', async () => {
try {
const tenMinutesAgo = new Date(Date.now() - 10 * 60 * 1000);
const { count } = await prisma.verifying.deleteMany({
where: {
created_at: { lte: tenMinutesAgo }
}
});
if (count) {
console.log(`🗑️ Deleted ${count} old verification code(s)`);
}
} catch (err) {
console.error('Error purging verifying table:', err);
}
}); */
// Every minute: delete any verifying records older than 10 minutes
schedule.scheduleJob('* * * * *', async () => {
try {
const result = await prisma.$executeRawUnsafe(`
DELETE FROM verifying
WHERE created_at + interval '10 minutes' < NOW()
`);
console.log(`🗑️ Deleted ${result} old verification code(s)`);
} catch (err) {
console.error('Error purging verifying table:', err);
}
});
// keep the process alive if you run this file directly
if (require.main === module) {
console.log('Verifier cleanup scheduler started');
process.stdin.resume();
}
module.exports = {};