Skip to content

Commit ffbacce

Browse files
committed
Increase time interval request to 1year for historical data pull
1 parent 0ae2179 commit ffbacce

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,15 @@ constructor(
9494
logger.info("Interval between dates is too short. Not requesting..")
9595
return emptySequence()
9696
}
97-
val endTime = (startOffset + defaultQueryRange).coerceAtMost(endDate)
98-
return route.generateRequests(user, startOffset, endTime, USER_MAX_REQUESTS)
97+
val timeSinceStart = Duration.between(startOffset, Instant.now())
98+
return if (timeSinceStart > HISTORICAL_DATA_THRESHOLD) {
99+
// Historical data: use 1-year chunks without max request limit
100+
val endTime = (startOffset + HISTORICAL_QUERY_RANGE).coerceAtMost(endDate)
101+
route.generateRequests(user, startOffset, endTime)
102+
} else {
103+
// Recent data: use normal chunking with max request limit
104+
route.generateRequests(user, startOffset, endDate, USER_MAX_REQUESTS)
105+
}
99106
}
100107

101108
fun handleResponse(
@@ -144,7 +151,7 @@ constructor(
144151
request.user,
145152
request.endDate,
146153
)
147-
userNextRequest[request.user.versionedId] = Instant.now().plus(BACK_OFF_TIME)
154+
userNextRequest[request.user.versionedId] = Instant.now().plus(SUCCESS_BACK_OFF_TIME)
148155
} else {
149156
userNextRequest[request.user.versionedId] = Instant.now().plus(BACK_OFF_TIME)
150157
}
@@ -240,9 +247,11 @@ constructor(
240247
private val ONE_DAY = Duration.ofDays(1L)
241248
private val TIME_AFTER_REQUEST = Duration.ofDays(30)
242249
private val USER_BACK_OFF_TIME = Duration.ofHours(12L)
243-
private val SUCCESS_BACK_OFF_TIME = Duration.ofMinutes(1L)
250+
private val SUCCESS_BACK_OFF_TIME = Duration.ofSeconds(10L)
244251
private val OFFSET_BUFFER = Duration.ofHours(12)
245-
private val USER_MAX_REQUESTS = 20
252+
private val USER_MAX_REQUESTS = 1000
253+
private val HISTORICAL_DATA_THRESHOLD = Duration.ofDays(365L)
254+
private val HISTORICAL_QUERY_RANGE = Duration.ofDays(365L)
246255
val JSON_FACTORY = JsonFactory()
247256
val JSON_READER = ObjectMapper(JSON_FACTORY).registerModule(JavaTimeModule()).reader()
248257
}

0 commit comments

Comments
 (0)