From 78581a50339919dd6cab1cc34625ea3eb08c11ec Mon Sep 17 00:00:00 2001 From: Torresmorah Date: Mon, 29 Jul 2024 15:25:56 -0600 Subject: [PATCH 1/2] fix(hapi): validate if the last schedule time is not undefined --- hapi/src/services/fio.service.js | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/hapi/src/services/fio.service.js b/hapi/src/services/fio.service.js index dfd0d8c6..0704fe23 100644 --- a/hapi/src/services/fio.service.js +++ b/hapi/src/services/fio.service.js @@ -347,16 +347,21 @@ const syncRewards = async () => { await updateRewards(producers) const scheduleTime = await getLastPaidScheduleTime() - - scheduleTime.setSeconds(scheduleTime.getSeconds() + 86400) - - const nextScheduleUpdate = Math.ceil((scheduleTime.getTime() - (new Date()).getTime())) - - if (nextScheduleUpdate > 0) { - console.log(`SYNCING FIO REWARDS - sync completed, next sync on ${scheduleTime.toISOString()}`) - setTimeout(syncRewards, nextScheduleUpdate) + const scheduleTimeMs = scheduleTime?.getTime() || 0 + + if (scheduleTimeMs > 0) { + scheduleTime.setSeconds(scheduleTime.getSeconds() + 86400) + + const nextScheduleUpdate = Math.ceil((scheduleTimeMs - (new Date()).getTime())) + + if (nextScheduleUpdate > 0) { + console.log(`SYNCING FIO REWARDS - sync completed, next sync on ${scheduleTime.toISOString()}`) + setTimeout(syncRewards, nextScheduleUpdate) + } else { + setTimeout(syncRewards, 5 * 60 * 1000) + } } else { - setTimeout(syncRewards, 5 * 60 * 1000) + setTimeout(syncRewards, 60 * 1000) } } } From f7e220484426d7d5e7a992766418a0bdbbab0072 Mon Sep 17 00:00:00 2001 From: Torresmorah Date: Mon, 29 Jul 2024 15:32:14 -0600 Subject: [PATCH 2/2] fix(hapi): fix next scheduleUpdate time --- hapi/src/services/fio.service.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hapi/src/services/fio.service.js b/hapi/src/services/fio.service.js index 0704fe23..225251d1 100644 --- a/hapi/src/services/fio.service.js +++ b/hapi/src/services/fio.service.js @@ -352,7 +352,7 @@ const syncRewards = async () => { if (scheduleTimeMs > 0) { scheduleTime.setSeconds(scheduleTime.getSeconds() + 86400) - const nextScheduleUpdate = Math.ceil((scheduleTimeMs - (new Date()).getTime())) + const nextScheduleUpdate = Math.ceil((scheduleTime.getTime() - (new Date()).getTime())) if (nextScheduleUpdate > 0) { console.log(`SYNCING FIO REWARDS - sync completed, next sync on ${scheduleTime.toISOString()}`)