Closed
Description
QueueClient will switch context whether current account is rate limited or not, while the context switching itself will unlock that account, cause the script to constantly switch between all loaded accounts no matter limited or not.
How about just remain the lock when switch context? To prevent using account that is already limited.
class RemainLocked(AccountsPool):
async def unlock(self, username: str, queue: str, req_count=0):
qs = f"""
UPDATE accounts SET
stats = json_set(stats, '$.{queue}', COALESCE(json_extract(stats, '$.{queue}'), 0) + {req_count}),
last_used = datetime({utc_ts()}, 'unixepoch')
WHERE username = :username
"""
await execute(self._db_file, qs, {"username": username})
async def get_for_queue(self, queue: str):
qs = f"""
SELECT * FROM accounts
WHERE active = true AND (
locks IS NULL
OR json_extract(locks, '$.{queue}') IS NULL
OR json_extract(locks, '$.{queue}') < datetime('now')
)
ORDER BY RANDOM()
LIMIT 1
"""
rs = await fetchone(self._db_file, qs)
return Account.from_rs(rs) if rs else None
Metadata
Assignees
Labels
No labels