Skip to content

Commit 7c21b7a

Browse files
✨ Increase retry defaults and add visible retry logging
1 parent b5f7d5c commit 7c21b7a

3 files changed

Lines changed: 16 additions & 16 deletions

File tree

asa_api_client/resources/base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@
3535
UpdateT = TypeVar("UpdateT", bound=BaseModel)
3636

3737
# Retry configuration
38-
DEFAULT_MAX_RETRIES = 3
39-
DEFAULT_INITIAL_DELAY = 1.0 # seconds
40-
DEFAULT_MAX_DELAY = 60.0 # seconds
38+
DEFAULT_MAX_RETRIES = 5
39+
DEFAULT_INITIAL_DELAY = 5.0 # seconds - Apple rate limits often need longer waits
40+
DEFAULT_MAX_DELAY = 120.0 # seconds
4141
DEFAULT_BACKOFF_FACTOR = 2.0
4242
RETRYABLE_STATUS_CODES = {429, 500, 502, 503, 504}
4343

asa_api_client/resources/custom_reports.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import builtins
88
import csv
99
import io
10+
import sys
1011
import time
1112
from datetime import date
1213
from typing import TYPE_CHECKING, Any
@@ -196,13 +197,13 @@ def _request(
196197
# Check if we should retry based on status code
197198
if response.status_code in RETRYABLE_STATUS_CODES and attempt < max_retries:
198199
delay = self._calculate_retry_delay(attempt, response)
199-
logger.warning(
200-
"Received %d (attempt %d/%d), retrying in %.1fs",
201-
response.status_code,
202-
attempt + 1,
203-
max_retries + 1,
204-
delay,
200+
# Log to both logger and stderr for visibility
201+
msg = (
202+
f"Rate limited ({response.status_code}), "
203+
f"attempt {attempt + 1}/{max_retries + 1}, retrying in {delay:.0f}s..."
205204
)
205+
logger.warning(msg)
206+
print(f"⏳ {msg}", file=sys.stderr)
206207
time.sleep(delay)
207208
continue
208209

@@ -261,13 +262,12 @@ async def _request_async(
261262
# Check if we should retry based on status code
262263
if response.status_code in RETRYABLE_STATUS_CODES and attempt < max_retries:
263264
delay = self._calculate_retry_delay(attempt, response)
264-
logger.warning(
265-
"Received %d (attempt %d/%d), retrying in %.1fs",
266-
response.status_code,
267-
attempt + 1,
268-
max_retries + 1,
269-
delay,
265+
msg = (
266+
f"Rate limited ({response.status_code}), "
267+
f"attempt {attempt + 1}/{max_retries + 1}, retrying in {delay:.0f}s..."
270268
)
269+
logger.warning(msg)
270+
print(f"⏳ {msg}", file=sys.stderr)
271271
await asyncio.sleep(delay)
272272
continue
273273

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "asa-api-client"
7-
version = "0.1.4"
7+
version = "0.1.5"
88
description = "A modern Python client for the Apple Search Ads API with full type safety and async support"
99
readme = "README.md"
1010
license = "MIT"

0 commit comments

Comments
 (0)