Skip to content

Commit

Permalink
code review: is only None tested?
Browse files Browse the repository at this point in the history
  • Loading branch information
bukzor committed Oct 11, 2023
1 parent 22d4ada commit 25e1d69
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/sentry/models/outbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,20 +529,17 @@ def lock_id(self, attrs: Iterable[str]) -> int:
def process_shard(
self, latest_shard_row: OutboxBase | None
) -> Generator[OutboxBase | None, None, None]:
flush_all: bool = not bool(latest_shard_row)
latest_shard_row = None
using: str = db.router.db_for_write(type(self))

shard_lock_id = self.lock_id(self.sharding_columns)
obtained_lock = True

try:
with connections[using].cursor() as cursor:
if flush_all:
cursor.execute("SELECT pg_try_advisory_lock(%s)", [shard_lock_id])
if not cursor.fetchone()[0]:
obtained_lock = False
else:
cursor.execute("SELECT pg_advisory_lock(%s)", [shard_lock_id])
cursor.execute("SELECT pg_try_advisory_lock(%s)", [shard_lock_id])
if not cursor.fetchone()[0]:
obtained_lock = False

if obtained_lock:
next_shard_row: OutboxBase | None
Expand Down

0 comments on commit 25e1d69

Please sign in to comment.