Skip to content

Commit

Permalink
Use API call to check if archive.org overloaded (#253)
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan authored Jan 5, 2022
1 parent a4c83f5 commit 1ef79e8
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions netkan/netkan/mirrorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from importlib.resources import read_text
from typing import Optional, List, Union, Iterable, BinaryIO, Dict, Any
import boto3
import requests
import github
import internetarchive
from jinja2 import Template
Expand Down Expand Up @@ -311,7 +310,7 @@ def process_queue(self, queue_name: str, timeout: int) -> None:
to_delete = []
for msg in messages:
# Check if archive.org is overloaded before each upload
if self.ia_overloaded():
if self.ia_session.s3_is_overloaded(access_key=self.ia_access):
logging.info('The Internet Archive is overloaded, try again later')
break
path = Path(self.ckm_repo.git_repo.working_dir, msg.body)
Expand Down Expand Up @@ -362,11 +361,6 @@ def _default_branch(self, ckan: Ckan) -> str:
return self._gh.get_repo(full_name).default_branch
return 'master'

def ia_overloaded(self) -> bool:
response = requests.get(
f'https://s3.us.archive.org/?check_limit=1&accesskey={self.ia_access}')
return response.status_code == 503 or response.json().get('over_limit')

def purge_epochs(self, dry_run: bool) -> None:
if dry_run:
logging.info('Dry run mode enabled, no changes will be made')
Expand Down

0 comments on commit 1ef79e8

Please sign in to comment.