Skip to content

Commit

Permalink
Merge pull request #1428 from edenia/fix/check-last-schedule-time-fio…
Browse files Browse the repository at this point in the history
…-blockchain

fix(hapi): validate if the last schedule time is not undefined
  • Loading branch information
xavier506 committed Jul 31, 2024
2 parents 482c709 + f7e2204 commit d3f62ce
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((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)
}
}
}
Expand Down

0 comments on commit d3f62ce

Please sign in to comment.