Temporary fix to prevent early token expiry
This commit is contained in:
parent
57f8417657
commit
db100bbf17
|
@ -27,12 +27,17 @@ proc fetchToken(): Future[Token] {.async.} =
|
||||||
echo "token parse fail"
|
echo "token parse fail"
|
||||||
return Token()
|
return Token()
|
||||||
|
|
||||||
|
let time = getTime()
|
||||||
result = Token(tok: resp[pos+3 .. pos+21], remaining: 187,
|
result = Token(tok: resp[pos+3 .. pos+21], remaining: 187,
|
||||||
reset: getTime() + 15.minutes, init: getTime())
|
reset: time + 15.minutes, init: time, lastUse: time)
|
||||||
|
|
||||||
proc expired(token: Token): bool {.inline.} =
|
proc expired(token: Token): bool {.inline.} =
|
||||||
const expirationTime = 2.hours
|
const
|
||||||
result = token.init < getTime() - expirationTime
|
expirationTime = 2.hours
|
||||||
|
maxLastUse = 1.hours
|
||||||
|
let time = getTime()
|
||||||
|
result = token.init < time - expirationTime or
|
||||||
|
token.lastUse < time - maxLastUse
|
||||||
|
|
||||||
proc isLimited(token: Token): bool {.inline.} =
|
proc isLimited(token: Token): bool {.inline.} =
|
||||||
token == nil or (token.remaining <= 1 and token.reset > getTime()) or
|
token == nil or (token.remaining <= 1 and token.reset > getTime()) or
|
||||||
|
@ -40,6 +45,7 @@ proc isLimited(token: Token): bool {.inline.} =
|
||||||
|
|
||||||
proc release*(token: Token) =
|
proc release*(token: Token) =
|
||||||
if token != nil and not token.expired:
|
if token != nil and not token.expired:
|
||||||
|
token.lastUse = getTime()
|
||||||
tokenPool.insert(token)
|
tokenPool.insert(token)
|
||||||
|
|
||||||
proc getToken*(): Future[Token] {.async.} =
|
proc getToken*(): Future[Token] {.async.} =
|
||||||
|
|
|
@ -9,6 +9,7 @@ type
|
||||||
remaining*: int
|
remaining*: int
|
||||||
reset*: Time
|
reset*: Time
|
||||||
init*: Time
|
init*: Time
|
||||||
|
lastUse*: Time
|
||||||
|
|
||||||
Error* = enum
|
Error* = enum
|
||||||
null = 0
|
null = 0
|
||||||
|
|
Loading…
Reference in New Issue