Add retry resilience to API calls#34
Open
salmanfarisvp wants to merge 2 commits intomasterfrom
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR aims to improve resilience of the QC automation script by retrying selected Screenly v4 API calls on requests.HTTPError, to reduce intermittent failures (notably an intermittent 401 during playlist creation).
Changes:
- Added
@retry(requests.HTTPError, tries=3, delay=5)to several API wrapper functions. - Updated
delete_playlist()to raise on HTTP failures and updated callers to handlerequests.HTTPError. - Expanded
create_qc_playlist()docstring to describe retry behavior.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| raise AssertionError("Not all online screens synchronized") | ||
|
|
||
|
|
||
| @retry(requests.HTTPError, tries=3, delay=5) |
| return qc_playlists | ||
|
|
||
|
|
||
| @retry(requests.HTTPError, tries=3, delay=5) |
| return True | ||
|
|
||
|
|
||
| @retry(requests.HTTPError, tries=3, delay=5) |
Comment on lines
+175
to
+180
| @retry(requests.HTTPError, tries=3, delay=5) | ||
| def create_qc_playlist(): | ||
| """ | ||
| Create a new QC playlist, populate it with random assets, | ||
| and assign it to all screens. | ||
| and assign it to all screens. Retries up to 3 times on transient | ||
| API errors (e.g. intermittent 401 from the PostgREST auth layer). |
| PLAYLIST_PREFIX = "QC" | ||
|
|
||
|
|
||
| @retry(requests.HTTPError, tries=3, delay=5) |
Collaborator
|
I'm against retries, Salman. Authentication should work 100% of the time. @salmanfarisvp, could you reliably reproduce it? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add
@retry(requests.HTTPError, tries=3, delay=5)to all API calls where retrying is safe:create_qc_playlist()— the direct fix for the intermittent 401get_ten_random_assets(),get_qc_playlist_ids(),get_all_screens_label_id()— read-only GET calls, always safe to retrydelete_playlist()— idempotent DELETE, safe to retryPOST calls that could create duplicates (
add_asset_to_playlist,assign_playlist_to_all_screens) are intentionally left without retry.Test plan