Software: Apache. PHP/8.1.30 uname -a: Linux server1.tuhinhossain.com 5.15.0-163-generic #173-Ubuntu SMP Tue Oct 14 17:51:00 UTC uid=1002(picotech) gid=1003(picotech) groups=1003(picotech),0(root) Safe-mode: OFF (not secure) /home/picotech/domains/rentals.picotech.app/public_html/server/jobs/ drwxrwxr-x | |
| Viewing file: Select action/file-type: import cron from 'node-cron';
import { Renter, RentPayment } from '../models/index.js';
cron.schedule('0 0 * * *', async () => {
await dailyTask();
});
// cron.schedule('* * * * *', async () => {
// console.log('Running task every minute:', new Date());
// await dailyTask();
// });
async function dailyTask() {
try {
const renters = await Renter.findAll({
order: [['created_at', 'DESC']],
});
const nowDate = new Date();
const monthNames = [
'January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December'
];
const currentMonth = monthNames[nowDate.getMonth()];
const currentYear = nowDate.getFullYear();
for (const renter of renters) {
const existingPayment = await RentPayment.findOne({
where: {
renter_id: renter.id,
month: currentMonth,
year: currentYear,
},
});
if (!existingPayment) {
await RentPayment.create({
renter_id: renter.id,
renterName: renter.name,
room_number: renter.room_id,
user_id: renter.user_id,
amount: renter.rent_amount,
due_date: nowDate,
status: 'pending',
month: currentMonth,
year: currentYear,
});
}
}
console.log('Rent requests created successfully.');
} catch (err) {
console.error('Failed to create rent requests:', err);
}
}
|
:: Command execute :: | |
--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.0092 ]-- |