Skip to content

Commit

Permalink
RDI-115-retry-logic
Browse files Browse the repository at this point in the history
Why these changes are being introduced:
The harvester needs retry logic to account for the observed behavior of various repositories during testing.

How this addresses that need:
* Add retry-related values to config.py
* Calls those values when instantiating a sickle client in oai.py

Side effects of this change:
None

Relevant ticket(s):
* https://mitlibraries.atlassian.net/browse/RDI-115
  • Loading branch information
ehanson8 committed Jul 7, 2022
1 parent e60f9f3 commit c456871
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions harvester/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

import sentry_sdk

DEFAULT_RETRY_AFTER = 10
MAX_RETRIES = 3
RETRY_STATUS_CODES = (429, 500, 503)


def configure_logger(logger: logging.Logger, verbose: bool) -> str:
if verbose:
Expand Down
9 changes: 8 additions & 1 deletion harvester/oai.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from sickle import Sickle
from sickle.models import Record

from harvester.config import DEFAULT_RETRY_AFTER, MAX_RETRIES, RETRY_STATUS_CODES

logger = logging.getLogger(__name__)


Expand All @@ -20,7 +22,12 @@ def __init__(
set_spec: Optional[str] = None,
) -> None:
self.source_url = source_url
self.client = Sickle(self.source_url)
self.client = Sickle(
self.source_url,
default_retry_after=DEFAULT_RETRY_AFTER,
max_retries=MAX_RETRIES,
retry_status_codes=RETRY_STATUS_CODES,
)
self.metadata_format = metadata_format
self._set_params(metadata_format, from_date, until_date, set_spec)

Expand Down

0 comments on commit c456871

Please sign in to comment.