1818from django .contrib .auth .models import User
1919from social_django .utils import load_strategy
2020from tethys_apps .base .function_extractor import TethysFunctionExtractor
21- from uit .exceptions import UITError
21+ from uit .exceptions import MaxRetriesError , UITError
2222from uit import AsyncClient , PbsScript , PbsJob , PbsArrayJob
2323from uit .pbs_script import PbsDirective
2424from tethys_compute .models .tethys_job import TethysJob
@@ -368,11 +368,11 @@ def process_intermediate_results_function(self):
368368 @process_intermediate_results_function .setter
369369 def process_intermediate_results_function (self , function ):
370370 if isinstance (function , str ):
371- self ._process_results_function = function
371+ self ._process_intermediate_results_function = function
372372 return
373373 module_path = inspect .getmodule (function ).__name__ .split ("." )
374374 module_path .append (function .__name__ )
375- self ._process_results_function = "." .join (module_path )
375+ self ._process_intermediate_results_function = "." .join (module_path )
376376
377377 @property
378378 def remote_workspace_id (self ):
@@ -547,8 +547,12 @@ async def update_status(self, status=None, *args, **kwargs):
547547
548548 # Update status if status not given and still pending/running
549549 elif update_needed and self .is_time_to_update ():
550- await self ._update_status (* args , ** kwargs )
551- self ._last_status_update = timezone .now ()
550+ try :
551+ await self ._update_status (* args , ** kwargs )
552+ self ._last_status_update = timezone .now ()
553+ except (MaxRetriesError , UITError ) as e :
554+ log .info (f"Unable to connect to { self .system } for user { self .user } due to the following error: { e } " )
555+ return
552556
553557 # Post-process status after update if old status was pending/running
554558 if update_needed :
@@ -617,18 +621,20 @@ def intermediate_transfer_interval_exceeded(self):
617621
618622 async def process_results (self ):
619623 """Process the results using the UIT Plus Python client."""
620- log .debug ("Started processing results for job: {}" . format ( self ) )
624+ log .debug (f "Started processing results for job: { self } " )
621625 await self .get_remote_files (self .transfer_output_files )
622626 self .completion_time = timezone .now ()
623627 self ._status = "COM"
624628 await self ._safe_save ()
625- log .debug ("Finished processing results for job: {}" .format (self ))
629+ if self .process_results_function :
630+ self .process_results_function (self )
631+ log .debug (f"Finished processing results for job: { self } " )
626632
627633 async def get_intermediate_results (self ):
628634 """Retrieve intermediate result files from the supercomputer."""
629635 if await self .get_remote_files (self .transfer_intermediate_files ):
630636 if self .process_intermediate_results_function :
631- self .process_intermediate_results_function ()
637+ self .process_intermediate_results_function (self )
632638
633639 def resolve_paths (self , paths ):
634640 resolved_paths = []
@@ -640,22 +646,29 @@ def resolve_paths(self, paths):
640646 resolved_paths .append (self .pbs_job .resolve_path (p ))
641647 return resolved_paths
642648
643- async def get_remote_files (self , remote_filenames ):
649+ async def get_remote_files (self , remote_paths ):
644650 """Transfer files from a directory on the super computer.
645651
646652 Args:
647- remote_filenames (List[str]): Files to retrieve from remote_dir
653+ remote_paths (List[str]): Files to retrieve from remote_dir
648654
649655 Returns:
650656 bool: True if all file transfers succeed.
651657 """
658+ remote_dirnames = []
659+ if isinstance (remote_paths , dict ):
660+ remote_dirnames = remote_paths .get ("dirs" , [])
661+ remote_filenames = remote_paths .get ("files" , [])
662+ else :
663+ remote_filenames = remote_paths
652664
653665 # Ensure the local transfer directory exists
654666 workspace = Path (self .workspace )
655667 success = True
656- remote_paths = self .resolve_paths (remote_filenames )
668+ remote_file_paths = self .resolve_paths (remote_filenames )
669+ remote_dir_paths = self .resolve_paths (remote_dirnames )
657670
658- for remote_path in remote_paths :
671+ for remote_path in remote_file_paths :
659672 rel_path = remote_path .relative_to (self .working_dir )
660673 local_path = workspace / rel_path
661674 local_path .parent .mkdir (parents = True , exist_ok = True )
@@ -668,6 +681,14 @@ async def get_remote_files(self, remote_filenames):
668681 success = False
669682 log .error ("Failed to get remote file: {}" .format (str (e )))
670683
684+ for remote_dir in remote_dir_paths :
685+ rel_path = remote_dir .relative_to (self .working_dir )
686+ local_dir = workspace / rel_path
687+ try :
688+ await self .client .get_dir (remote_dir = remote_dir , local_dir = local_dir )
689+ except Exception as e :
690+ log .exception (e )
691+
671692 return success
672693
673694 @_ensure_connected
0 commit comments