Files
modstagram-back/services/OfferReplyCron.js
payacom c302aea177 4.1.3
2026-09-13 21:32:36 +03:30

25 lines
915 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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 }