diff --git a/pyproject.toml b/pyproject.toml index b867a5d..e5c8660 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "rda_python_common" -version = "3.0.9" +version = "3.0.10" authors = [ { name="Zaihua Ji", email="zji@ucar.edu" }, ] diff --git a/src/rda_python_common/pg_file.py b/src/rda_python_common/pg_file.py index 23ccd21..e67b62d 100644 --- a/src/rda_python_common/pg_file.py +++ b/src/rda_python_common/pg_file.py @@ -233,9 +233,9 @@ def copy_gdex_file(self, tofile, fromfile, tohost = None, fromhost = None, logac if self.pgcmp(thost, self.OHOST, 1) == 0: return self.local_copy_object(tofile, fromfile, None, None, logact) elif self.pgcmp(thost, self.BHOST, 1) == 0: - return self.local_copy_backup(tofile, fromfile, self.QPOINTS['B'], logact) + return self.wait_copy_backup(tofile, fromfile, self.QPOINTS['B'], logact) elif self.pgcmp(thost, self.DHOST, 1) == 0: - return self.local_copy_backup(tofile, fromfile, self.QPOINTS['D'], logact) + return self.wait_copy_backup(tofile, fromfile, self.QPOINTS['D'], logact) else: return self.local_copy_remote(tofile, fromfile, tohost, logact) elif self.pgcmp(thost, self.LHOST, 1) == 0: @@ -664,6 +664,25 @@ def local_copy_backup(self, tofile, fromfile, endpoint = None, logact = 0): if not endpoint: endpoint = self.PGLOG['BACKUPEP'] return self.endpoint_copy_endpoint(tofile, fromfile, endpoint, 'gdex-glade', logact) + # Copy a local file to Quasar backup tape system and wait until the Globus task is done + # for callers that cannot handle a self.FINISH return + def wait_copy_backup(self, tofile, fromfile, endpoint = None, logact = 0): + """Copy a local GLADE file to the Quasar backup endpoint and wait for completion. + + Args: + tofile (str): Destination path on the backup endpoint (leading '/dsNNN.N/'). + fromfile (str): Source local path (leading '/data/' or '/decsdata/'). + endpoint (str | None): Globus endpoint name; defaults to PGLOG['BACKUPEP']. + logact (int): Logging action flags; default 0. + + Returns: + int: self.SUCCESS or self.FAILURE. + """ + if not endpoint: endpoint = self.PGLOG['BACKUPEP'] + ret = self.local_copy_backup(tofile, fromfile, endpoint, logact) + if ret == self.FINISH: ret = self.check_globus_finished(tofile, endpoint, logact) + return ret + # Copy a Quasar backup file to local Globus endpoint # tofile - target file name, leading with /data/ or /decsdata/ # fromfile - source file name, leading with /dsnnn.n/ @@ -671,6 +690,9 @@ def local_copy_backup(self, tofile, fromfile, endpoint = None, logact = 0): def backup_copy_local(self, tofile, fromfile, endpoint = None, logact = 0): """Copy a file from the Quasar backup endpoint to a local GLADE path via Globus. + Waits for the Globus task to finish before returning, so the local file is + complete for the caller. + Args: tofile (str): Destination local path (leading '/data/' or '/decsdata/'). fromfile (str): Source backup path (leading '/dsNNN.N/'). @@ -678,10 +700,12 @@ def backup_copy_local(self, tofile, fromfile, endpoint = None, logact = 0): logact (int): Logging action flags; default 0. Returns: - int: self.SUCCESS, self.FAILURE, or self.FINISH. + int: self.SUCCESS or self.FAILURE. """ if not endpoint: endpoint = self.PGLOG['BACKUPEP'] - return self.endpoint_copy_endpoint(tofile, fromfile, 'gdex-glade', endpoint, logact) + ret = self.endpoint_copy_endpoint(tofile, fromfile, 'gdex-glade', endpoint, logact) + if ret == self.FINISH: ret = self.check_globus_finished(tofile, 'gdex-glade', logact) + return ret # Copy a remote file to local # tofile - target file name