-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 Source Shopify: Allow the known
HTTP errors
to be retried more th…
…an once for the BULK streams (#37589)
- Loading branch information
Showing
10 changed files
with
403 additions
and
325 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ requires = [ "poetry-core>=1.0.0",] | |
build-backend = "poetry.core.masonry.api" | ||
|
||
[tool.poetry] | ||
version = "2.0.7" | ||
version = "2.0.8" | ||
name = "source-shopify" | ||
description = "Source CDK implementation for Shopify." | ||
authors = [ "Airbyte <[email protected]>",] | ||
|
463 changes: 223 additions & 240 deletions
463
airbyte-integrations/connectors/source-shopify/source_shopify/shopify_graphql/bulk/job.py
Large diffs are not rendered by default.
Oops, something went wrong.
50 changes: 50 additions & 0 deletions
50
airbyte-integrations/connectors/source-shopify/source_shopify/shopify_graphql/bulk/retry.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Copyright (c) 2024 Airbyte, Inc., all rights reserved. | ||
|
||
from functools import wraps | ||
from time import sleep | ||
from typing import Any, Callable, Final, Optional, Tuple, Type | ||
|
||
from airbyte_cdk import AirbyteLogger | ||
|
||
from .exceptions import ShopifyBulkExceptions | ||
|
||
BULK_RETRY_ERRORS: Final[Tuple] = ( | ||
ShopifyBulkExceptions.BulkJobBadResponse, | ||
ShopifyBulkExceptions.BulkJobUnknownError, | ||
) | ||
|
||
|
||
def bulk_retry_on_exception(logger: AirbyteLogger, more_exceptions: Optional[Tuple[Type[Exception], ...]] = None) -> Callable: | ||
""" | ||
A decorator to retry a function when specified exceptions are raised. | ||
:param logger: Number of times to retry. | ||
:param more_exceptions: A tuple of exception types to catch. | ||
""" | ||
|
||
def decorator(func: Callable) -> Callable: | ||
@wraps(func) | ||
def wrapper(self, *args, **kwargs) -> Any: | ||
# mandatory class attributes | ||
max_retries = self._job_max_retries | ||
stream_name = self.stream_name | ||
backoff_time = self._job_backoff_time | ||
|
||
current_retries = 0 | ||
while True: | ||
try: | ||
return func(self, *args, **kwargs) | ||
except BULK_RETRY_ERRORS or more_exceptions as ex: | ||
current_retries += 1 | ||
if current_retries > max_retries: | ||
logger.error("Exceeded retry limit. Giving up.") | ||
raise | ||
else: | ||
logger.warning( | ||
f"Stream `{stream_name}`: {ex}. Retrying {current_retries}/{max_retries} after {backoff_time} seconds." | ||
) | ||
sleep(backoff_time) | ||
|
||
return wrapper | ||
|
||
return decorator |
14 changes: 14 additions & 0 deletions
14
airbyte-integrations/connectors/source-shopify/source_shopify/shopify_graphql/bulk/status.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Copyright (c) 2024 Airbyte, Inc., all rights reserved. | ||
|
||
from enum import Enum | ||
|
||
|
||
class ShopifyBulkJobStatus(Enum): | ||
CREATED = "CREATED" | ||
CANCELED = "CANCELED" | ||
CANCELING = "CANCELING" | ||
COMPLETED = "COMPLETED" | ||
RUNNING = "RUNNING" | ||
FAILED = "FAILED" | ||
TIMEOUT = "TIMEOUT" | ||
ACCESS_DENIED = "ACCESS_DENIED" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.