mirror of
https://github.com/InsanusMokrassar/SauceNaoAPI.git
synced 2024-12-23 13:17:11 +00:00
update consts calling
This commit is contained in:
parent
555e1da355
commit
d5cfb7d36e
@ -1,4 +0,0 @@
|
|||||||
package com.github.insanusmokrassar.SauceNaoAPI
|
|
||||||
|
|
||||||
const val LONG_TIME_LIMIT_MILLIS: Int = 1 * 24 * 60 * 60 * 1000
|
|
||||||
const val SHORT_TIME_LIMIT_MILLIS: Int = 30 * 1000
|
|
@ -1,5 +1,7 @@
|
|||||||
package com.github.insanusmokrassar.SauceNaoAPI
|
package com.github.insanusmokrassar.SauceNaoAPI
|
||||||
|
|
||||||
|
import com.github.insanusmokrassar.SauceNaoAPI.additional.LONG_TIME_RECALCULATING_MILLIS
|
||||||
|
import com.github.insanusmokrassar.SauceNaoAPI.additional.SHORT_TIME_RECALCULATING_MILLIS
|
||||||
import com.github.insanusmokrassar.SauceNaoAPI.exceptions.sauceNaoAPIException
|
import com.github.insanusmokrassar.SauceNaoAPI.exceptions.sauceNaoAPIException
|
||||||
import com.github.insanusmokrassar.SauceNaoAPI.models.SauceNaoAnswer
|
import com.github.insanusmokrassar.SauceNaoAPI.models.SauceNaoAnswer
|
||||||
import io.ktor.client.HttpClient
|
import io.ktor.client.HttpClient
|
||||||
@ -44,11 +46,11 @@ data class SauceNaoAPI(
|
|||||||
val answer = makeRequest(requestBuilder)
|
val answer = makeRequest(requestBuilder)
|
||||||
callback.resumeWith(Result.success(answer))
|
callback.resumeWith(Result.success(answer))
|
||||||
|
|
||||||
val sleepUntil = if (answer.header.longRemaining == 0) {
|
val sleepUntil = if (answer.header.longRemaining < 1) {
|
||||||
getMostOldestInLongPeriod() ?.plusMillis(LONG_TIME_LIMIT_MILLIS)
|
getMostOldestInLongPeriod() ?.plusMillis(LONG_TIME_RECALCULATING_MILLIS)
|
||||||
} else {
|
} else {
|
||||||
if (answer.header.shortRemaining == 0) {
|
if (answer.header.shortRemaining < 1) {
|
||||||
getMostOldestInShortPeriod() ?.plusMillis(SHORT_TIME_LIMIT_MILLIS)
|
getMostOldestInShortPeriod() ?.plusMillis(SHORT_TIME_RECALCULATING_MILLIS)
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
@ -137,7 +139,7 @@ data class SauceNaoAPI(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun clearRequestTimes(relatedTo: DateTime = DateTime.now()) {
|
private fun clearRequestTimes(relatedTo: DateTime = DateTime.now()) {
|
||||||
val limitValue = relatedTo.minusMillis(LONG_TIME_LIMIT_MILLIS)
|
val limitValue = relatedTo.minusMillis(LONG_TIME_RECALCULATING_MILLIS)
|
||||||
|
|
||||||
requestsSendTimes.removeAll {
|
requestsSendTimes.removeAll {
|
||||||
it < limitValue
|
it < limitValue
|
||||||
@ -153,7 +155,7 @@ data class SauceNaoAPI(
|
|||||||
private fun getMostOldestInShortPeriod(): DateTime? {
|
private fun getMostOldestInShortPeriod(): DateTime? {
|
||||||
val now = DateTime.now()
|
val now = DateTime.now()
|
||||||
|
|
||||||
val limitTime = now.minusMillis(SHORT_TIME_LIMIT_MILLIS)
|
val limitTime = now.minusMillis(SHORT_TIME_RECALCULATING_MILLIS)
|
||||||
|
|
||||||
clearRequestTimes(now)
|
clearRequestTimes(now)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user