diff --git a/hapi/src/services/fio.service.js b/hapi/src/services/fio.service.js index dfd0d8c6..225251d1 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((scheduleTime.getTime() - (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) } } }