Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reorder try/catch for start/finish redis key #3370

Merged
merged 1 commit into from
Jul 1, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
)