Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shorter logging for mirrorer upload failures #350

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions netkan/netkan/mirrorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,18 +319,23 @@ def try_mirror(self, ckan: CkanMirror) -> bool:
if download_file:
logging.info('Uploading %s', ckan.mirror_item())
item = internetarchive.Item(self.ia_session, ckan.mirror_item())
item.upload_file(download_file.name, ckan.mirror_filename(),
ckan.item_metadata,
ckan.download_headers)
source_url = ckan.source_download(self._default_branch(ckan))
if source_url:
with tempfile.NamedTemporaryFile() as tmp:
logging.info('Attempting to archive source from %s', source_url)
download_stream_to_file(source_url, tmp)
tmp.flush()
item.upload_file(tmp.name, ckan.mirror_source_filename(),
ckan.item_metadata,
ckan.source_download_headers(tmp.name))
try:
item.upload_file(download_file.name, ckan.mirror_filename(),
ckan.item_metadata,
ckan.download_headers)
source_url = ckan.source_download(self._default_branch(ckan))
if source_url:
with tempfile.NamedTemporaryFile() as tmp:
logging.info('Attempting to archive source from %s', source_url)
download_stream_to_file(source_url, tmp)
tmp.flush()
item.upload_file(tmp.name, ckan.mirror_source_filename(),
ckan.item_metadata,
ckan.source_download_headers(tmp.name))
except Exception as exc: # pylint: disable=broad-except
logging.error('Upload of %s failed: %s',
ckan.mirror_item(), exc)
return False
return True
logging.error("Failed to find or download %s", ckan.download)
return False
Expand Down