File tree Expand file tree Collapse file tree 1 file changed +9
-1
lines changed
oura-library/src/main/kotlin/org/radarbase/oura/request Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Original file line number Diff line number Diff 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)
You can’t perform that action at this time.
0 commit comments