You have a list of titles. You want one task per title in Google Tasks. You have retry logic for a single call. How do you combine them so one flaky task doesn't fail the whole batch?
Loop the titles, and for each one retry up to N times? Track how many succeed?
Exactly. Each iteration is independent — one title, one retry loop, one outcome. Failures at the end of the retry raise, and the outer loop catches them so the next title gets a fresh start:
for title in titles:
try:
task_ids.append(create_one_with_retry(title))
except Exception:
print(f"Gave up on '{title}'")So the per-item try/except is the outer safety net, and the retry loop is the inner fast-recovery. Two layers, one for reruns and one for skips?
Exactly. The outer catch lets the batch complete even if one title is permanently broken. Here's the full function, retry inline inside the loop:
def bulk_create_with_retry(titles: list, max_attempts: int) -> list:
task_ids = []
for title in titles:
for attempt in range(1, max_attempts + 1):
try:
result = toolset.execute_action(Action.GOOGLETASKS_CREATE_TASK, {"title": title})
task_ids.append(result["id"])
break
except Exception as exc:
if attempt == max_attempts:
print(f"Gave up on '{title}': {exc}")
task_ids.append("")
break
print(f"Created {sum(1 for t in task_ids if t)}/{len(titles)} tasks")
return task_idsWhy break after appending? Doesn't the loop already end on the last attempt?
The break is essential — without it, a successful early attempt would keep retrying. break exits the inner retry loop so the outer for title moves to the next title. break on final failure also exits so we fall through to the next title with a sentinel empty string.
So even if the fifth title times out forever, the first four and the sixth still get created — partial success instead of total failure?
Partial success with a clear record of what failed. Every pipeline in Week 4 relies on this shape.
TL;DR: Outer loop over items, inner retry loop per item, break to advance once handled.
break on success — stop retrying once one attempt worksbreak on final failure — fall through to the next item with a sentinel"" — distinguishes 'failed' from 'not attempted' in the returned list| Layer | Purpose |
|---|---|
outer for title in titles | iterate the batch |
inner for attempt in range(...) | retry one title up to N times |
You have a list of titles. You want one task per title in Google Tasks. You have retry logic for a single call. How do you combine them so one flaky task doesn't fail the whole batch?
Loop the titles, and for each one retry up to N times? Track how many succeed?
Exactly. Each iteration is independent — one title, one retry loop, one outcome. Failures at the end of the retry raise, and the outer loop catches them so the next title gets a fresh start:
for title in titles:
try:
task_ids.append(create_one_with_retry(title))
except Exception:
print(f"Gave up on '{title}'")So the per-item try/except is the outer safety net, and the retry loop is the inner fast-recovery. Two layers, one for reruns and one for skips?
Exactly. The outer catch lets the batch complete even if one title is permanently broken. Here's the full function, retry inline inside the loop:
def bulk_create_with_retry(titles: list, max_attempts: int) -> list:
task_ids = []
for title in titles:
for attempt in range(1, max_attempts + 1):
try:
result = toolset.execute_action(Action.GOOGLETASKS_CREATE_TASK, {"title": title})
task_ids.append(result["id"])
break
except Exception as exc:
if attempt == max_attempts:
print(f"Gave up on '{title}': {exc}")
task_ids.append("")
break
print(f"Created {sum(1 for t in task_ids if t)}/{len(titles)} tasks")
return task_idsWhy break after appending? Doesn't the loop already end on the last attempt?
The break is essential — without it, a successful early attempt would keep retrying. break exits the inner retry loop so the outer for title moves to the next title. break on final failure also exits so we fall through to the next title with a sentinel empty string.
So even if the fifth title times out forever, the first four and the sixth still get created — partial success instead of total failure?
Partial success with a clear record of what failed. Every pipeline in Week 4 relies on this shape.
TL;DR: Outer loop over items, inner retry loop per item, break to advance once handled.
break on success — stop retrying once one attempt worksbreak on final failure — fall through to the next item with a sentinel"" — distinguishes 'failed' from 'not attempted' in the returned list| Layer | Purpose |
|---|---|
outer for title in titles | iterate the batch |
inner for attempt in range(...) | retry one title up to N times |
Create a free account to get started. Paid plans unlock all tracks.