mirror of
https://github.com/InsanusMokrassar/SauceNaoAPI.git
synced 2024-11-26 16:28:42 +00:00
fix recover of short and long quota in quota manager
This commit is contained in:
parent
bb20fd8d7c
commit
275686b3ad
@ -8,6 +8,7 @@ import kotlinx.coroutines.channels.Channel
|
|||||||
import kotlinx.io.core.Closeable
|
import kotlinx.io.core.Closeable
|
||||||
import org.joda.time.DateTime
|
import org.joda.time.DateTime
|
||||||
import kotlin.coroutines.suspendCoroutine
|
import kotlin.coroutines.suspendCoroutine
|
||||||
|
import kotlin.math.max
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
|
|
||||||
class RequestQuotaManager (
|
class RequestQuotaManager (
|
||||||
@ -42,17 +43,13 @@ class RequestQuotaManager (
|
|||||||
shortQuota = min(newShortQuota, shortMaxQuota)
|
shortQuota = min(newShortQuota, shortMaxQuota)
|
||||||
|
|
||||||
when {
|
when {
|
||||||
shortQuota < 1 -> timeManager.getMostOldestInShortPeriod() ?.millis ?.plus(SHORT_TIME_RECALCULATING_MILLIS) ?: let {
|
longQuota < 1 -> (timeManager.getMostOldestInLongPeriod() ?: DateTime.now()).millis + LONG_TIME_RECALCULATING_MILLIS
|
||||||
shortQuota = 1
|
shortQuota < 1 -> (timeManager.getMostOldestInShortPeriod() ?: DateTime.now()).millis + SHORT_TIME_RECALCULATING_MILLIS
|
||||||
null
|
|
||||||
}
|
|
||||||
longQuota < 1 -> timeManager.getMostOldestInLongPeriod() ?.millis ?.plus(LONG_TIME_RECALCULATING_MILLIS) ?: let {
|
|
||||||
longQuota = 1
|
|
||||||
null
|
|
||||||
}
|
|
||||||
else -> null
|
else -> null
|
||||||
} ?.let {
|
} ?.also {
|
||||||
delay(it - DateTime.now().millis)
|
delay(it - DateTime.now().millis)
|
||||||
|
shortQuota = max(shortQuota, 1)
|
||||||
|
longQuota = max(longQuota, 1)
|
||||||
}
|
}
|
||||||
Unit
|
Unit
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user