4.1.3
This commit is contained in:
24
services/OfferReplyCron.js
Normal file
24
services/OfferReplyCron.js
Normal 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 }
|
||||
Reference in New Issue
Block a user