Skip to content

Commit 8fc83c1

Browse files
committed
Fix updating offsets when no records found for historical data pull
1 parent d8e094d commit 8fc83c1

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

oura-library/src/main/kotlin/org/radarbase/oura/request/OuraRequestGenerator.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,18 @@ constructor(
195195
val offset = records.maxByOrNull { it -> it.offset }?.offset
196196
if (offset != null) {
197197
logger.info("Writing ${records.size} records to offsets...")
198+
val maxOffsetTime = Instant.ofEpochSecond(offset)
199+
// For older data, offset is end date
200+
val dataAge = Duration.between(maxOffsetTime, Instant.now())
201+
val nextOffset = if (dataAge <= Duration.ofDays(7)) {
202+
maxOffsetTime.plus(OFFSET_BUFFER)
203+
} else {
204+
maxOf(maxOffsetTime.plus(OFFSET_BUFFER), request.endDate)
205+
}
198206
ouraOffsetManager.updateOffsets(
199207
request.route,
200208
request.user,
201-
Instant.ofEpochSecond(offset).plus(OFFSET_BUFFER),
209+
nextOffset,
202210
)
203211
val nextRequestTime = Instant.now().plus(SUCCESS_BACK_OFF_TIME)
204212
val key = routeKey(request.route, request.user)

0 commit comments

Comments
 (0)