This commit is contained in:
payacom
2026-09-13 21:32:36 +03:30
parent 90c5f94b57
commit c302aea177
49 changed files with 4063 additions and 920 deletions

View File

@@ -0,0 +1,24 @@
const cron = require('node-cron')
const { refundExpiredOfferCommissions } = require('../utils/offerReplyGate')
let ioInstance = null
/** Called once from index.js right after the socket.io server is created — cron jobs have no `req`. */
function setIo (io) {
ioInstance = io
}
// هر ۱۵ دقیقه یک‌بار — چون مهلت ۱۲ ساعته است، بازه‌ی کوتاه‌تر از cron ماهانه‌ی
// پروژه‌ها (ProjectCron.js) لازم است تا بازگشتِ وجه با تأخیرِ زیاد انجام نشود
cron.schedule('*/15 * * * *', async () => {
try {
const refundedCount = await refundExpiredOfferCommissions(ioInstance)
if (refundedCount > 0) {
console.log(`[OfferReplyCron] refunded ${refundedCount} expired offer commission(s)`)
}
} catch (error) {
console.error('[OfferReplyCron] error:', error)
}
})
module.exports = { setIo }