Skip to content

Add retry resilience to API calls#34

Open
salmanfarisvp wants to merge 2 commits intomasterfrom
retry-on-api-call-v2
Open

Add retry resilience to API calls#34
salmanfarisvp wants to merge 2 commits intomasterfrom
retry-on-api-call-v2

Conversation

@salmanfarisvp
Copy link
Copy Markdown
Collaborator

@salmanfarisvp salmanfarisvp commented Apr 30, 2026

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 401
  • get_ten_random_assets(), get_qc_playlist_ids(), get_all_screens_label_id() — read-only GET calls, always safe to retry
  • delete_playlist() — idempotent DELETE, safe to retry

POST calls that could create duplicates (add_asset_to_playlist, assign_playlist_to_all_screens) are intentionally left without retry.

Test plan

  • Job still exits green on a clean run

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 handle requests.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)
@renatgalimov
Copy link
Copy Markdown
Collaborator

I'm against retries, Salman.

Authentication should work 100% of the time.

@salmanfarisvp, could you reliably reproduce it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants