Skip to content

Commit

Permalink
fix(hapi): validate if the last schedule time is not undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
Torresmorah committed Jul 29, 2024
1 parent 482c709 commit 78581a5
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions hapi/src/services/fio.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down

0 comments on commit 78581a5

Please sign in to comment.