Skip to content

Commit

Permalink
enh: allow to abort the compress step of a job
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmueller committed Aug 30, 2021
1 parent ca3f3ba commit 71097d9
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
0.6.4
- enh: automatically respwan job tasks on connection errors (#26)
- enh: allow to abort the "compress" step of a job
- enh: when loading upload tasks that have already been loaded
before, tell the user how many there were
0.6.3
Expand Down
2 changes: 1 addition & 1 deletion dcoraid/gui/upload/widget_tablecell_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def refresh_visibility(self, job):
else:
self.tb_error.hide()

if state == "transfer":
if state in ["compress", "transfer"]:
self.tb_abort.show()
else:
self.tb_abort.hide()
Expand Down
27 changes: 10 additions & 17 deletions dcoraid/upload/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def monitor_callback(self, monitor):
def retry_upload(self):
"""Retry uploading resources when an error occured"""
if self.state in ["abort", "error"]:
self.set_state("parcel")
self.set_state("init")
else:
raise ValueError("Can only retry upload in error state!")

Expand Down Expand Up @@ -387,22 +387,15 @@ def task_upload_resources(self):
continue
else:
# Normal upload.
try:
dataset.add_resource(
dataset_id=self.dataset_id,
path=path,
resource_name=resource_name,
resource_dict=resource_supplement,
api=self.api,
exist_ok=True,
monitor_callback=self.monitor_callback)
self.paths_uploaded.append(path)
except SystemExit:
# This thread has just been killed
self.start_time = None
self.file_bytes_uploaded[ii] = 0
self.set_state("abort")
return
dataset.add_resource(
dataset_id=self.dataset_id,
path=path,
resource_name=resource_name,
resource_dict=resource_supplement,
api=self.api,
exist_ok=True,
monitor_callback=self.monitor_callback)
self.paths_uploaded.append(path)
self.end_time = time.perf_counter()
self.set_state("online")
else:
Expand Down
6 changes: 6 additions & 0 deletions dcoraid/upload/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ def abort_job(self, dataset_id):
# https://github.com/requests/toolbelt/issues/297
self.daemon_upload.terminate()
self.daemon_upload = UploadDaemon(self.jobs)
elif job.state == "compress":
job.set_state("abort")
self.daemon_compress.terminate()
self.daemon_compress = CompressDaemon(self.jobs)

def add_job(self, upload_job):
"""Add an UploadJob to the queue
Expand Down Expand Up @@ -328,6 +332,8 @@ def run(self):
+ "\nDCOR-Aid will retry in 10s!"
time.sleep(10)
job.set_state(self.job_trigger_state)
except SystemExit:
job.set_state("abort")
except BaseException:
# Set job to error state and let the user figure
# out what to do next.
Expand Down
7 changes: 4 additions & 3 deletions tests/test_upload_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import pytest

import dcoraid
import dcoraid.api
from dcoraid.upload.dataset import create_dataset
from dcoraid.upload import job, task

Expand Down Expand Up @@ -67,9 +68,9 @@ def test_dataset_id_already_exists_active_fails():
# attempt to upload the task
uj.task_compress_resources()
assert uj.state == "parcel"
uj.task_upload_resources()
assert uj.state == "error"
assert "Access denied" in str(uj.traceback)
with pytest.raises(dcoraid.api.APIAuthorizationError,
match=""):
uj.task_upload_resources()


def test_dataset_id_does_not_exist():
Expand Down

0 comments on commit 71097d9

Please sign in to comment.