Skip to content

Commit

Permalink
Reverted Waiting until changes
Browse files Browse the repository at this point in the history
  • Loading branch information
nagyDarius committed Sep 21, 2021
1 parent c1f0e59 commit 7f2fe19
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ import com.google.api.client.http.HttpResponseException
import org.dxworks.githubminer.http.GithubHttpResponse
import org.dxworks.githubminer.utils.GithubResponseHeaderExtractor
import java.time.LocalDateTime
import java.time.ZoneId
import java.time.ZoneOffset
import java.time.ZonedDateTime

class RateLimit(githubHttpResponse: GithubHttpResponse) : GithubResponseHeaderExtractor(githubHttpResponse) {
val requestLimit: Int = getNumberHeaderValue(RATE_LIMIT, 5000).toInt()
val remainingRequests: Int = getNumberHeaderValue(REMAINING_REQUESTS, 5000).toInt()
var resetTimestamp: ZonedDateTime = ZonedDateTime.now()
var resetTimestamp: LocalDateTime = LocalDateTime.MIN

companion object {
private const val RATE_LIMIT = "X-RateLimit-Limit"
Expand All @@ -23,11 +21,11 @@ class RateLimit(githubHttpResponse: GithubHttpResponse) : GithubResponseHeaderEx
init {
val resetUtcSeconds = getNumberHeaderValue(RESET_TIMESTAMP, 0)
if (resetUtcSeconds != 0) resetTimestamp =
LocalDateTime.ofEpochSecond(resetUtcSeconds.toLong(), 0, ZoneOffset.UTC).atZone(ZoneId.systemDefault())
LocalDateTime.ofEpochSecond(resetUtcSeconds.toLong(), 0, ZoneOffset.UTC)
}

fun resetTimestampFromAbuse(e: HttpResponseException) {
resetTimestamp = ZonedDateTime.now().plusSeconds(
resetTimestamp = LocalDateTime.now().plusSeconds(
try {
getHeaderValue(RETRY_AFTER, e.headers).toLong()
} catch (e: Exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import org.dxworks.utils.java.rest.client.providers.CompositeHttpRequestInitiali
import org.dxworks.utils.java.rest.client.response.HttpResponse
import org.slf4j.LoggerFactory
import java.lang.reflect.Type
import java.time.ZoneOffset
import java.time.ZonedDateTime

open class GithubHttpClient(private val githubTokens: List<String>, private val githubBasePath: String) :
Expand Down Expand Up @@ -151,11 +152,9 @@ open class GithubHttpClient(private val githubTokens: List<String>, private val
private fun waitUntilSoonestRateLimitReset() {
val waitUntil = tokenRateLimits.values.minOf { it.resetTimestamp }
log.info("Waiting until $waitUntil")
val now = ZonedDateTime.now()
if (waitUntil > now)
Thread.sleep(
(waitUntil.toEpochSecond() - now.toEpochSecond() + 1) * 1000
)
Thread.sleep(
(waitUntil.toEpochSecond(ZoneOffset.UTC) - ZonedDateTime.now(ZoneOffset.UTC).toEpochSecond() + 1) * 1000
)
getTokenRateLimits()
}

Expand Down

0 comments on commit 7f2fe19

Please sign in to comment.