1
0
mirror of synced 2026-01-17 12:07:50 -05:00
Files
airbyte/airbyte-integrations/connectors/source-google-sheets/google_sheets_source/client.py
Alexandre Girard 19a20f0efc 🐛 Source Google Sheets: Retry on server errors (#13446)
* Retry on server errors

* retry on any 5XX

* bump version

* rename function for clarity

* reset

* delete unused code

* auto-bump connector version

Co-authored-by: Octavia Squidington III <octavia-squidington-iii@users.noreply.github.com>
2022-06-02 18:28:45 -07:00

40 lines
1.3 KiB
Python

#
# Copyright (c) 2022 Airbyte, Inc., all rights reserved.
#
from typing import Dict, List
import backoff
from googleapiclient import errors
from requests import codes as status_codes
from .helpers import SCOPES, Helpers
def give_up(error):
code = error.resp.status
# Stop retrying if it's not a problem with the rate limit or on the server end
return not (code == status_codes.TOO_MANY_REQUESTS or 500 <= code < 600)
class GoogleSheetsClient:
def __init__(self, credentials: Dict[str, str], scopes: List[str] = SCOPES):
self.client = Helpers.get_authenticated_sheets_client(credentials, scopes)
@backoff.on_exception(backoff.expo, errors.HttpError, max_time=120, giveup=give_up)
def get(self, **kwargs):
return self.client.get(**kwargs).execute()
@backoff.on_exception(backoff.expo, errors.HttpError, max_time=120, giveup=give_up)
def create(self, **kwargs):
return self.client.create(**kwargs).execute()
@backoff.on_exception(backoff.expo, errors.HttpError, max_time=120, giveup=give_up)
def get_values(self, **kwargs):
return self.client.values().batchGet(**kwargs).execute()
@backoff.on_exception(backoff.expo, errors.HttpError, max_time=120, giveup=give_up)
def update_values(self, **kwargs):
return self.client.values().batchUpdate(**kwargs).execute()