mirror of
https://github.com/InsanusMokrassar/SauceNaoAPI.git
synced 2024-11-30 02:08:43 +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 org.joda.time.DateTime
|
||||
import kotlin.coroutines.suspendCoroutine
|
||||
import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
|
||||
class RequestQuotaManager (
|
||||
@ -42,17 +43,13 @@ class RequestQuotaManager (
|
||||
shortQuota = min(newShortQuota, shortMaxQuota)
|
||||
|
||||
when {
|
||||
shortQuota < 1 -> timeManager.getMostOldestInShortPeriod() ?.millis ?.plus(SHORT_TIME_RECALCULATING_MILLIS) ?: let {
|
||||
shortQuota = 1
|
||||
null
|
||||
}
|
||||
longQuota < 1 -> timeManager.getMostOldestInLongPeriod() ?.millis ?.plus(LONG_TIME_RECALCULATING_MILLIS) ?: let {
|
||||
longQuota = 1
|
||||
null
|
||||
}
|
||||
longQuota < 1 -> (timeManager.getMostOldestInLongPeriod() ?: DateTime.now()).millis + LONG_TIME_RECALCULATING_MILLIS
|
||||
shortQuota < 1 -> (timeManager.getMostOldestInShortPeriod() ?: DateTime.now()).millis + SHORT_TIME_RECALCULATING_MILLIS
|
||||
else -> null
|
||||
} ?.let {
|
||||
} ?.also {
|
||||
delay(it - DateTime.now().millis)
|
||||
shortQuota = max(shortQuota, 1)
|
||||
longQuota = max(longQuota, 1)
|
||||
}
|
||||
Unit
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user