Skip to content

Commit

Permalink
Cancel a task if a specific type of event occurs
Browse files Browse the repository at this point in the history
  • Loading branch information
iparask committed Mar 3, 2025
1 parent bb540f2 commit b89b51c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
11 changes: 10 additions & 1 deletion hera_librarian/async_transfers/globus.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import globus_sdk

from hera_librarian.transfer import TransferStatus

from hera_librarian.utils import GLOBUS_ERROR_EVENTS
from .core import CoreAsyncTransferManager


Expand Down Expand Up @@ -332,6 +332,15 @@ def transfer_status(self, settings: "ServerSettings") -> TransferStatus:
return TransferStatus.COMPLETED
elif task_doc["status"] == "FAILED":
return TransferStatus.FAILED
# When there are errors, better fail the task and try again. There is
# a different check for faults to make the state transition as clear as
# possible.
elif task_doc["faults"] > 0:
task_event_list = transfer_client.task_event_list(self.task_id)
for event in task_event_list:
if event["code"] in GLOBUS_ERROR_EVENTS and event["is_error"]:
return TransferStatus.FAILED
return TransferStatus.FAILED
else: # "status" == "ACTIVE"
return TransferStatus.INITIATED

Expand Down
18 changes: 18 additions & 0 deletions hera_librarian/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,21 @@ def get_size_from_path(path):
size += os.path.getsize(dirname + "/" + f)

return size


# --- Globus Events ---
GLOBUS_EVENTS = [
"AMBIGUOUS_PATH",
"IS_A_DIRECTORY",
"EXPIRED",
"FILE_NOT_FOUND",
"FILE_SIZE_CHANGED",
"INVALID_PATH_NAME",
"INVALID_SERVICE_CREDENTIAL",
"INVALID_SYMLINK",
"LIMIT_EXCEEDED",
"NO_CREDENTIALS",
"NO_SPACE_LEFT",
"PERMISSION_DENIED",
"QUOTA_EXCEEDED",
]

0 comments on commit b89b51c

Please sign in to comment.