Skip to content

Commit

Permalink
Reorder try/catch for start/finish redis key (#3370)
Browse files Browse the repository at this point in the history
  • Loading branch information
vicky-g authored Jul 1, 2022
1 parent 40bc65e commit c882989
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions discovery-provider/src/tasks/update_track_is_available.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,9 @@ def update_track_is_available(self) -> None:
timeout=DEFAULT_LOCK_TIMEOUT_SECONDS,
)

try:
have_lock = update_lock.acquire(blocking=False)
if have_lock:
have_lock = update_lock.acquire(blocking=False)
if have_lock:
try:
redis.set(
UPDATE_TRACK_IS_AVAILABLE_START_REDIS_KEY,
datetime.now(tz=timezone.utc).strftime("%Y-%m-%d %H:%M:%S.%f %Z"),
Expand All @@ -238,21 +238,20 @@ def update_track_is_available(self) -> None:
fetch_unavailable_track_ids_in_network(session, redis)

update_tracks_is_available_status(db, redis)
else:
logger.warning(
"update_track_is_available.py | Lock not acquired",
exc_info=True,
except Exception as e:
logger.error(
"update_track_is_available.py | Fatal error in main loop", exc_info=True
)

except Exception as e:
logger.error(
"update_track_is_available.py | Fatal error in main loop", exc_info=True
)
raise e
finally:
if have_lock:
update_lock.release()
raise e
finally:
redis.set(
UPDATE_TRACK_IS_AVAILABLE_FINISH_REDIS_KEY,
datetime.now(tz=timezone.utc).strftime("%Y-%m-%d %H:%M:%S.%f %Z"),
)
if have_lock:
update_lock.release()
else:
logger.warning(
"update_track_is_available.py | Lock not acquired",
exc_info=True,
)

0 comments on commit c882989

Please sign in to comment.