Skip to content

Commit

Permalink
increase time for lock invoice disatcher
Browse files Browse the repository at this point in the history
  • Loading branch information
callebtc committed Jul 6, 2024
1 parent 20099a4 commit aa90f9f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions cashu/core/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def _is_lock_exception(e):
while time.time() - start_time < timeout:
trial += 1
try:
logger.trace("Connecting to database (trial: {trial})")
logger.trace("Connecting to database trial: {trial} ({random_int})")
async with self.engine.begin() as conn: # type: ignore
assert isinstance(conn, AsyncConnection)
logger.trace("Connected to database. Starting transaction")
Expand All @@ -230,11 +230,11 @@ def _is_lock_exception(e):
wconn, lock_table, lock_select_statement
)
logger.trace(
f"> Yielding connection. Lock: {lock_table} - {random_int} - {trial}"
f"> Yielding connection. Lock: {lock_table} - trial {trial} ({random_int})"
)
yield wconn
logger.trace(
f"< Connection yielded. Unlock: {lock_table} - {random_int} - {trial}"
f"< Connection yielded. Unlock: {lock_table} - trial {trial} ({random_int})"
)
return
except psycopg2.errors.LockNotAvailable as e:
Expand All @@ -245,7 +245,9 @@ def _is_lock_exception(e):
await _handle_lock_retry(retry_delay, timeout, start_time)
else:
raise e
raise Exception("failed to acquire database lock")
raise Exception(
f"failed to acquire database lock on {lock_table} after {timeout}s and {trial} trials ({random_int})"
)

async def acquire_lock(
self,
Expand Down
2 changes: 1 addition & 1 deletion cashu/mint/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async def invoice_callback_dispatcher(self, checking_id: str) -> None:
async with self.db.get_connection(
lock_table="mint_quotes",
lock_select_statement=f"checking_id='{checking_id}'",
lock_timeout=1,
lock_timeout=5,
) as conn:
quote = await self.crud.get_mint_quote(
checking_id=checking_id, db=self.db, conn=conn
Expand Down

0 comments on commit aa90f9f

Please sign in to comment.