Add retry resilience to API calls#34
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) |
| @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) |
|
I'm against retries, Salman. Authentication should work 100% of the time. @salmanfarisvp, could you reliably reproduce it? |
renatgalimov
left a comment
There was a problem hiding this comment.
Rejected. The issue doesn't have a programmatic solution. Keep bothering me, Ivan and Pavel until there are not retries needed.
|
@renatgalimov noted. Other than retry what method you suggest? As per your suggestion, I created a new PR with api v4.1/ . |
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