Fixed algorithm error with calculating canUpdate due to wrapping around the day at midnight

This commit is contained in:
nise.moe 2024-02-22 15:35:34 +01:00
parent 4003dd81d4
commit 2d3b7b0817

View File

@ -8,6 +8,7 @@ import org.jooq.DSLContext
import org.springframework.http.ResponseEntity import org.springframework.http.ResponseEntity
import org.springframework.messaging.simp.SimpMessagingTemplate import org.springframework.messaging.simp.SimpMessagingTemplate
import org.springframework.stereotype.Service import org.springframework.stereotype.Service
import java.time.Duration
import java.time.OffsetDateTime import java.time.OffsetDateTime
import java.time.ZoneOffset import java.time.ZoneOffset
@ -43,12 +44,13 @@ class UpdateUserQueueService(
.limit(1) .limit(1)
.fetchOneInto(OffsetDateTime::class.java) .fetchOneInto(OffsetDateTime::class.java)
var canUpdate = !isProcessing var canUpdate = !isProcessing;
if(lastCompletedUpdateQueue != null) { if (lastCompletedUpdateQueue != null) {
val now = OffsetDateTime.now(ZoneOffset.UTC) val now = OffsetDateTime.now(ZoneOffset.UTC)
val hoursSinceLastUpdate = now.hour - lastCompletedUpdateQueue.hour val duration = Duration.between(lastCompletedUpdateQueue, now)
val hoursSinceLastUpdate = duration.toHours()
if(hoursSinceLastUpdate < USER_UPDATE_INTERVAL_HOURS) if (hoursSinceLastUpdate < USER_UPDATE_INTERVAL_HOURS)
canUpdate = false canUpdate = false
} }