use stdlib http client

This commit is contained in:
drpepper66 2023-11-17 23:09:45 +01:00
parent f6ca1a3f2a
commit c8c606f96e
1 changed files with 6 additions and 5 deletions

View File

@ -1,7 +1,7 @@
#SPDX-License-Identifier: AGPL-3.0-only
import std/[httpclient, asyncdispatch, times, json, random, sequtils, strutils, tables, packedsets, os, uri]
import nimcrypto
import types, http_pool
import types
import experimental/parser/guestaccount
# max requests at a time per account to avoid race conditions
@ -216,13 +216,12 @@ proc updateAccountPool*(cfg: Config) {.async.} =
while true:
if accountPool.len == 0:
let pool = HttpPool()
log "fetching more accounts from service"
let client = newAsyncHttpClient()
try:
pool.use(newHttpHeaders()):
let resp = await c.get($(cfg.guestAccountsPoolUrl ? {"id": cfg.guestAccountsPoolId, "auth": cfg.guestAccountsPoolAuth}))
let resp = await client.get($(cfg.guestAccountsPoolUrl ? {"id": cfg.guestAccountsPoolId, "auth": cfg.guestAccountsPoolAuth}))
let guestAccounts = await resp.body
log "status code from service: ", resp.status
@ -233,6 +232,8 @@ proc updateAccountPool*(cfg: Config) {.async.} =
except Exception as e:
log "failed to fetch from accounts service: ", e.msg
finally:
client.close()
accountPool.keepItIf(not it.hasExpired)