wisdom #62
@@ -1029,7 +1029,7 @@ class NotifikasiWaService {
|
|||||||
|
|
||||||
this.stopCronJob(currentDeviceId);
|
this.stopCronJob(currentDeviceId);
|
||||||
|
|
||||||
const scheduleResult = await this.scheduleReminderJob(
|
const scheduleResult = await this.scheduleCustomReminderJob(
|
||||||
currentDeviceId,
|
currentDeviceId,
|
||||||
deviceName,
|
deviceName,
|
||||||
startDateObj,
|
startDateObj,
|
||||||
@@ -1041,7 +1041,7 @@ class NotifikasiWaService {
|
|||||||
|
|
||||||
if (isEndDatePassed) {
|
if (isEndDatePassed) {
|
||||||
console.log(`⏰ End_date sudah terlewati, mengirim reminder sekarang untuk ${deviceName}`);
|
console.log(`⏰ End_date sudah terlewati, mengirim reminder sekarang untuk ${deviceName}`);
|
||||||
const sendResult = await this.sendReminderNow(
|
const sendResult = await this.sendCustomReminderNow(
|
||||||
currentDeviceId,
|
currentDeviceId,
|
||||||
deviceName,
|
deviceName,
|
||||||
startDateObj,
|
startDateObj,
|
||||||
@@ -1069,7 +1069,7 @@ class NotifikasiWaService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async scheduleReminderJob(deviceId, deviceName, startDateObj, endDateObj) {
|
async scheduleCustomReminderJob(deviceId, deviceName, startDateObj, endDateObj) {
|
||||||
try {
|
try {
|
||||||
const now = dayjs().tz(this.timeZone);
|
const now = dayjs().tz(this.timeZone);
|
||||||
|
|
||||||
@@ -1090,11 +1090,9 @@ class NotifikasiWaService {
|
|||||||
const isEndDatePassed = now.isAfter(endDateObj) || now.isSame(endDateObj);
|
const isEndDatePassed = now.isAfter(endDateObj) || now.isSame(endDateObj);
|
||||||
|
|
||||||
if (isEndDatePassed) {
|
if (isEndDatePassed) {
|
||||||
await this.sendReminderNow(deviceId, deviceName, startDateObj, endDateObj);
|
await this.sendCustomReminderNow(deviceId, deviceName, startDateObj, endDateObj);
|
||||||
} else {
|
|
||||||
console.log(`End_date untuk ${deviceName} belum terlewati, menunggu...`);
|
|
||||||
this.rescheduleReminderCheck(deviceId, deviceName, startDateObj, endDateObj);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`Gagal mengirim reminder untuk ${deviceName}:`, error);
|
console.error(`Gagal mengirim reminder untuk ${deviceName}:`, error);
|
||||||
}
|
}
|
||||||
@@ -1128,7 +1126,7 @@ class NotifikasiWaService {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (!checkNotifExist) {
|
if (!checkNotifExist) {
|
||||||
await this.sendReminderNow(deviceId, deviceName, startDateObj, endDateObj);
|
await this.sendCustomReminderNow(deviceId, deviceName, startDateObj, endDateObj);
|
||||||
} else {
|
} else {
|
||||||
console.log(`Reminder untuk ${deviceName} sudah pernah dikirim`);
|
console.log(`Reminder untuk ${deviceName} sudah pernah dikirim`);
|
||||||
}
|
}
|
||||||
@@ -1166,28 +1164,7 @@ class NotifikasiWaService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async rescheduleReminderCheck(deviceId, deviceName, startDateObj, endDateObj) {
|
async sendCustomReminderNow(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) {
|
|
||||||
try {
|
try {
|
||||||
console.log(`Mengirim reminder untuk ${deviceName}`);
|
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() {
|
async restartWhatsapp() {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user