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

fix(resume-xmlupload): make resource counting more user friendly (DEV-3397) #864

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/dsp_tools/commands/resume_xmlupload/resume_xmlupload.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
from dsp_tools.commands.xmlupload.xmlupload import cleanup_upload
from dsp_tools.commands.xmlupload.xmlupload import upload_resources
from dsp_tools.utils.connection_live import ConnectionLive
from dsp_tools.utils.create_logger import get_logger

logger = get_logger(__name__)


def resume_xmlupload(
Expand All @@ -33,6 +36,17 @@ def resume_xmlupload(
uploaded because there is an error in it
"""
upload_state = _read_upload_state_from_disk(server)
previous_successful = len(upload_state.iri_resolver_lookup)
previous_failed = len(upload_state.failed_uploads)
previous_total = previous_successful + previous_failed
msg = (
f"Resuming upload for project {upload_state.config.shortcode} on server {server}. "
f"Number of resources uploaded until now: {previous_total}"
)
if previous_failed:
msg += f" ({previous_failed} of them failed)"
logger.info(msg)
print("\n==========================\n" + msg + "\n==========================\n")

con = ConnectionLive(server)
con.login(user, password)
Expand Down
15 changes: 11 additions & 4 deletions src/dsp_tools/commands/xmlupload/xmlupload.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,11 +403,15 @@ def _upload_resources(
media_previously_ingested=config.media_previously_uploaded,
)

total_res = len(resources)
total_res = len(resources) + len(iri_resolver.lookup)
previous_successful = len(iri_resolver.lookup)
previous_failed = len(failed_uploads)
previous_total = previous_successful + previous_failed
# if the interrupt_after value is not set, the upload will not be interrupted
interrupt_after = config.interrupt_after or total_res + 1

for i, resource in enumerate(resources.copy()):
current_res = i + 1 + previous_total
if i >= interrupt_after:
raise XmlUploadInterruptedError(f"Interrupted: Maximum number of resources was reached ({interrupt_after})")
success, media_info = handle_media_info(
Expand All @@ -427,12 +431,12 @@ def _upload_resources(
else:
# resource creation succeeded: update the iri_resolver and remove the resource from the list
iri, label = res
_tidy_up_resource_creation(iri, label, iri_resolver, resource, i + 1, total_res) # type: ignore[arg-type]
_tidy_up_resource_creation(iri, label, iri_resolver, resource, current_res, total_res) # type: ignore[arg-type]
except BaseException as err:
if res and res[0]:
# creation succeeded, but during tidy up, a Keyboard Interrupt occurred. tidy up again before escalating
iri, label = res
_tidy_up_resource_creation(iri, label, iri_resolver, resource, i + 1, total_res)
_tidy_up_resource_creation(iri, label, iri_resolver, resource, current_res, total_res)
else:
# unhandled exception during resource creation
failed_uploads.append(resource.res_id)
Expand Down Expand Up @@ -527,7 +531,10 @@ def _handle_upload_error(
if failed_uploads:
msg += f"Independently from this, there were some resources that could not be uploaded: {failed_uploads}\n"

logger.exception(msg)
if exit_code == 1:
logger.exception(msg)
else:
logger.info(msg)
print(msg)

sys.exit(exit_code)
Expand Down