wisdom #62

Merged
zain_arif merged 7 commits from wisdom into main 2026-06-25 06:41:43 +00:00
Showing only changes of commit 5112090a35 - Show all commits

View File

@@ -1029,7 +1029,7 @@ class NotifikasiWaService {
this.stopCronJob(currentDeviceId);
const scheduleResult = await this.scheduleReminderJob(
const scheduleResult = await this.scheduleCustomReminderJob(
currentDeviceId,
deviceName,
startDateObj,
@@ -1041,7 +1041,7 @@ class NotifikasiWaService {
if (isEndDatePassed) {
console.log(`⏰ End_date sudah terlewati, mengirim reminder sekarang untuk ${deviceName}`);
const sendResult = await this.sendReminderNow(
const sendResult = await this.sendCustomReminderNow(
currentDeviceId,
deviceName,
startDateObj,
@@ -1069,7 +1069,7 @@ class NotifikasiWaService {
}
}
async scheduleReminderJob(deviceId, deviceName, startDateObj, endDateObj) {
async scheduleCustomReminderJob(deviceId, deviceName, startDateObj, endDateObj) {
try {
const now = dayjs().tz(this.timeZone);
@@ -1090,11 +1090,9 @@ class NotifikasiWaService {
const isEndDatePassed = now.isAfter(endDateObj) || now.isSame(endDateObj);
if (isEndDatePassed) {
await this.sendReminderNow(deviceId, deviceName, startDateObj, endDateObj);
} else {
console.log(`End_date untuk ${deviceName} belum terlewati, menunggu...`);
this.rescheduleReminderCheck(deviceId, deviceName, startDateObj, endDateObj);
await this.sendCustomReminderNow(deviceId, deviceName, startDateObj, endDateObj);
}
} catch (error) {
console.error(`Gagal mengirim reminder untuk ${deviceName}:`, error);
}
@@ -1128,7 +1126,7 @@ class NotifikasiWaService {
);
if (!checkNotifExist) {
await this.sendReminderNow(deviceId, deviceName, startDateObj, endDateObj);
await this.sendCustomReminderNow(deviceId, deviceName, startDateObj, endDateObj);
} else {
console.log(`Reminder untuk ${deviceName} sudah pernah dikirim`);
}
@@ -1166,28 +1164,7 @@ class NotifikasiWaService {
}
}
async rescheduleReminderCheck(deviceId, deviceName, startDateObj, endDateObj) {
const checkInterval = setInterval(async () => {
const now = dayjs().tz(this.timeZone);
const isEndDatePassed = now.isAfter(endDateObj) || now.isSame(endDateObj);
if (isEndDatePassed) {
clearInterval(checkInterval);
console.log(`End_date terlewati untuk ${deviceName}, mengirim reminder...`);
try {
await this.sendReminderNow(deviceId, deviceName, startDateObj, endDateObj);
} catch (error) {
console.error(`Gagal mengirim reminder untuk ${deviceName}:`, error);
}
}
}, 60000);
this.cronJobs.set(`interval_${deviceId}`, {
intervalId: checkInterval
});
}
async sendReminderNow(deviceId, deviceName, startDateObj, endDateObj) {
async sendCustomReminderNow(deviceId, deviceName, startDateObj, endDateObj) {
try {
console.log(`Mengirim reminder untuk ${deviceName}`);
@@ -1347,37 +1324,6 @@ class NotifikasiWaService {
}
getActiveCronJobs() {
const activeJobs = [];
for (const [key, value] of this.cronJobs) {
if (!key.startsWith('cron_') && !key.startsWith('interval_')) {
activeJobs.push({
deviceId: key,
nextRun: value.nextRun,
startDate: value.startDate,
endDate: value.endDate
});
}
}
return activeJobs;
}
stopAllCronJobs() {
for (const [key, value] of this.cronJobs) {
if (value.timeoutId) {
clearTimeout(value.timeoutId);
}
if (value.intervalId) {
clearInterval(value.intervalId);
}
if (value.cronTask) {
value.cronTask.stop();
}
}
this.cronJobs.clear();
console.log('Semua cron job dihentikan');
}
async restartWhatsapp() {
try {