Skip to content

Commit

Permalink
retry on timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
JingLin0 committed Sep 4, 2023
1 parent 6fbf897 commit 046c55a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions tap_facebook/streams.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import singer
import time
from requests.exceptions import ReadTimeout
from typing import Any, Sequence, Union, Optional, Dict, cast, List
from datetime import timedelta, datetime, date
from dateutil import parser
Expand All @@ -10,6 +11,7 @@
from facebook_business.adobjects.adsinsights import AdsInsights
from facebook_business.adobjects.adreportrun import AdReportRun


logger = singer.get_logger()


Expand All @@ -19,7 +21,6 @@ def __init__(self, config):
self.bookmark_key = "date_start"

def stream(self, account_ids: Sequence[str], state: dict, tap_stream_id: str):

for account_id in account_ids:
state = self.process_account(
account_id, tap_stream_id=tap_stream_id, state=state
Expand Down Expand Up @@ -101,7 +102,7 @@ def process_account(
else:
time_ranges = [(since, until)]
try:
for (start, stop) in time_ranges:
for start, stop in time_ranges:
timerange = {"since": str(start), "until": str(stop)}
params = {
"level": "ad",
Expand Down Expand Up @@ -193,7 +194,9 @@ def __get_start(self, account_id, state: dict, tap_stream_id: str) -> datetime:
logger.info(f"using 'start_date' from previous state: {current_bookmark}")
return parser.isoparse(current_bookmark)

@backoff.on_exception(backoff.expo, FacebookRequestError, max_tries=5, base=5)
@backoff.on_exception(
backoff.expo, (FacebookRequestError, ReadTimeoutError), max_tries=5, base=5
)
def __retrieve_job(self, async_job) -> AdReportRun:
job = cast(AdReportRun, async_job.api_get())
return job
Expand Down

0 comments on commit 046c55a

Please sign in to comment.