Skip to content

Commit fc3b979

Browse files
committed
Add backoff time when request successful to space out requests
1 parent 0673b47 commit fc3b979

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ constructor(
111111
request.user,
112112
Instant.ofEpochSecond(offset).plus(Duration.ofMillis(500)),
113113
)
114+
userNextRequest[request.user.versionedId] = Instant.now().plus(SUCCESS_BACK_OFF_TIME)
114115
} else {
115116
if (request.startDate.plus(TIME_AFTER_REQUEST).isBefore(Instant.now())) {
116117
ouraOffsetManager.updateOffsets(
@@ -196,6 +197,7 @@ constructor(
196197
private val ONE_DAY = 1L
197198
private val TIME_AFTER_REQUEST = Duration.ofDays(30)
198199
private val USER_BACK_OFF_TIME = Duration.ofMinutes(2L)
200+
private val SUCCESS_BACK_OFF_TIME = Duration.ofSeconds(3L)
199201
private val USER_MAX_REQUESTS = 20
200202
val JSON_FACTORY = JsonFactory()
201203
val JSON_READER = ObjectMapper(JSON_FACTORY).registerModule(JavaTimeModule()).reader()

0 commit comments

Comments
 (0)