Skip to content

Commit

Permalink
Improve wrap_query_exceptions code
Browse files Browse the repository at this point in the history
Based on @ewjoachim's feedback.
  • Loading branch information
Éric Lemoine committed Jun 18, 2020
1 parent 894b4b6 commit 082b819
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions procrastinate/aiopg_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ def wrap_query_exceptions(coro: CoroutineFunction) -> CoroutineFunction:
@functools.wraps(coro)
async def wrapped(*args, **kwargs):
final_exc = None
max_tries = (
args[0]._pool.maxsize + 1 if args and getattr(args[0], "_pool", None) else 1
)
try:
max_tries = args[0]._pool.maxconn + 1
except Exception:
max_tries = 1
for _ in range(max_tries):
try:
return await coro(*args, **kwargs)
Expand Down
7 changes: 4 additions & 3 deletions procrastinate/psycopg2_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ def wrap_query_exceptions(func: Callable) -> Callable:
@functools.wraps(func)
def wrapped(*args, **kwargs):
final_exc = None
max_tries = (
args[0]._pool.maxconn + 1 if args and getattr(args[0], "_pool", None) else 1
)
try:
max_tries = args[0]._pool.maxconn + 1
except Exception:
max_tries = 1
for _ in range(max_tries):
try:
return func(*args, **kwargs)
Expand Down

0 comments on commit 082b819

Please sign in to comment.