I have to delete all the OTP
records which expired after every three months
.
In /sheduled-tasks/OTPRecords.js
const prisma = require("../services/prisma");
const THREE_MONTHS = 1000 * 60 * 60 * 24 * 90;
async function deleteExpiredOTPRecords() {
console.log("first");
setInterval(async () => {
console.log("INTERVAL", THREE_MONTHS);
const today = new Date();
const yesterday = new Date(today.setDate(today.getDate() - 1));
const records = await prisma.otp.deleteMany({
where: { expires_at: { lte: yesterday } },
});
console.log(records);
}, THREE_MONTHS);
}
module.exports = deleteExpiredOTPRecords;
In /index.js
deleteExpiredOTPRecords();
I was expecting this function run after every THREE_MONTHS
but my code runs indefinitely in a loop, i am unable to figure out where am i going wrong.
OUTPUT
INTERVAL 7776000000
INTERVAL 7776000000
{ count: 0 }
{ count: 0 }
INTERVAL 7776000000
{ count: 0 }
INTERVAL 7776000000
{ count: 0 }
INTERVAL 7776000000
{ count: 0 }
INTERVAL 7776000000
{ count: 0 }
INTERVAL 7776000000
{ count: 0 }
INTERVAL 7776000000
{ count: 0 }
INTERVAL 7776000000
{ count: 0 }
INTERVAL 7776000000
{ count: 0 }
INTERVAL 7776000000
{ count: 0 }
INTERVAL 7776000000
{ count: 0 }
INTERVAL 7776000000
INTERVAL 7776000000
{ count: 0 }
^C(node:33075) [DEP0164] DeprecationWarning: Implicit coercion to integer for exit code is
deprecated.