Spaces:
Sleeping
Sleeping
File size: 1,096 Bytes
43d9b90 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | const env = require('../config/env');
const { syncDueReminderOccurrencesForAll } = require('../services/reminders.service');
let intervalHandle = null;
let isRunning = false;
async function runOnce() {
if (isRunning) {
return;
}
isRunning = true;
try {
const synced = await syncDueReminderOccurrencesForAll({ limit: 120 });
if (synced.length > 0) {
console.log(`[push-worker] Synced due reminder occurrences: ${synced.length}`);
}
} catch (error) {
console.error('[push-worker] Failed to sync due reminders.');
console.error(error);
} finally {
isRunning = false;
}
}
function startReminderPushWorker() {
if (intervalHandle || !env.pushReminderWorkerEnabled) {
return;
}
const intervalMs = Math.max(env.pushReminderWorkerIntervalSeconds, 15) * 1000;
setTimeout(() => {
runOnce();
}, 2000);
intervalHandle = setInterval(() => {
runOnce();
}, intervalMs);
console.log(`[push-worker] Reminder push worker started (${Math.floor(intervalMs / 1000)}s interval).`);
}
module.exports = {
startReminderPushWorker,
};
|