25 lines
915 B
JavaScript
25 lines
915 B
JavaScript
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 }
|