Skip to content

Commit

Permalink
TDL-18751:[tap-zendesk] Implement backoff to handle 409 from Zendesk …
Browse files Browse the repository at this point in the history
…API (#107)
  • Loading branch information
nitingaikwad1 authored May 12, 2022
1 parent 86c1fb2 commit 27430a8
Show file tree
Hide file tree
Showing 2 changed files with 318 additions and 146 deletions.
15 changes: 14 additions & 1 deletion tap_zendesk/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,16 @@ def is_fatal(exception):

return 400 <=status_code < 500

def should_retry_error(exception):
"""
Return true if exception is required to retry otherwise return false
"""
if isinstance(exception, ZendeskConflictError):
return True
if isinstance(exception,Exception) and isinstance(exception.args[0][1],ConnectionResetError):
return True
return False

def raise_for_error(response):
""" Error handling method which throws custom error. Class for each error defined above which extends `ZendeskError`.
This method map the status code with `ERROR_CODE_EXCEPTION_MAPPING` dictionary and accordingly raise the error.
Expand All @@ -130,6 +140,10 @@ def raise_for_error(response):
response.status_code, {}).get("raise_exception", ZendeskError)
raise exc(message, response) from None

@backoff.on_exception(backoff.expo,
(ZendeskConflictError),
max_tries=10,
giveup=lambda e: not should_retry_error(e))
@backoff.on_exception(backoff.expo,
(HTTPError, ZendeskError), # Added support of backoff for all unhandled status codes.
max_tries=10,
Expand Down Expand Up @@ -158,7 +172,6 @@ def get_cursor_based(url, access_token, request_timeout, cursor=None, **kwargs):

if cursor:
params['page[after]'] = cursor

response = call_api(url, request_timeout, params=params, headers=headers)
response_json = response.json()

Expand Down
Loading

0 comments on commit 27430a8

Please sign in to comment.