fix sleeps, better exception handling

This commit is contained in:
drpepper66 2023-11-17 22:48:51 +01:00
parent 98cc15e78c
commit ab321c9b10
2 changed files with 19 additions and 10 deletions

View file

@ -210,11 +210,17 @@ proc updateAccountPool*(cfg: Config) {.async.} =
if not cfg.guestAccountsUsePool:
return
# wait for a few seconds before fetching guest accounts, so that
# /.well-known/... is served correctly
await sleepAsync(10 * 1000)
while true:
if accountPool.len == 0:
let pool = HttpPool()
log "fetching more accounts from service"
try:
pool.use(newHttpHeaders()):
let resp = await c.get("$1?id=$2&auth=$3" % [cfg.guestAccountsPoolUrl, cfg.guestAccountsPoolId, cfg.guestAccountsPoolAuth])
let guestAccounts = await resp.body
@ -225,9 +231,12 @@ proc updateAccountPool*(cfg: Config) {.async.} =
if line != "":
accountPool.add parseGuestAccount(line)
except Exception as e:
log "failed to fetch from accounts service: ", e.msg
accountPool.keepItIf(not it.hasExpired)
await sleepAsync(3600)
await sleepAsync(3600 * 1000)
proc getAuthHash*(cfg: Config): string =
if cfg.guestAccountsPoolAuth == "":

View file

@ -7,6 +7,6 @@ import ".."/[types, auth]
proc createAuthRouter*(cfg: Config) =
router auth:
get "/.well-known/nitter-request-auth":
get "/.well-known/nitter-auth":
cond cfg.guestAccountsUsePool
resp Http200, {"content-type": "text/plain"}, getAuthHash(cfg)