From a5a3946a7a77c1af08f0505a2563a21ad69700f4 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Wed, 22 Mar 2017 12:23:49 -0400 Subject: [PATCH] Fix problem with cleaning up jobs in local runner. Fixes #3801 (broken in b78287f as part of #3291). --- lib/galaxy/jobs/runners/__init__.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/galaxy/jobs/runners/__init__.py b/lib/galaxy/jobs/runners/__init__.py index ba186503144d..ae8bf35b57df 100644 --- a/lib/galaxy/jobs/runners/__init__.py +++ b/lib/galaxy/jobs/runners/__init__.py @@ -404,6 +404,8 @@ def __init__( self, job_wrapper, job_destination ): self.job_wrapper = job_wrapper self.job_destination = job_destination + self.cleanup_file_attributes = [ 'job_file', 'output_file', 'error_file', 'exit_code_file' ] + def set_defaults( self, files_dir ): if self.job_wrapper is not None: id_tag = self.job_wrapper.get_id_tag() @@ -427,6 +429,19 @@ def default_job_file( files_dir, id_tag ): def default_exit_code_file( files_dir, id_tag ): return os.path.join( files_dir, 'galaxy_%s.ec' % id_tag ) + def cleanup( self ): + for file in [ getattr( self, a ) for a in self.cleanup_file_attributes if hasattr( self, a ) ]: + try: + os.unlink( file ) + except Exception as e: + # TODO: Move this prefix stuff to a method so we don't have dispatch on attributes we may or may + # have. + if not hasattr( self, "job_id" ): + prefix = "(%s)" % self.job_wrapper.get_id_tag() + else: + prefix = "(%s/%s)" % ( self.job_wrapper.get_id_tag(), self.job_id ) + log.debug( "%s Unable to cleanup %s: %s" % (prefix, file, str( e ) ) ) + class AsynchronousJobState( JobState ): """ @@ -453,8 +468,6 @@ def __init__( self, files_dir=None, job_wrapper=None, job_id=None, job_file=None self.set_defaults( files_dir ) - self.cleanup_file_attributes = [ 'job_file', 'output_file', 'error_file', 'exit_code_file' ] - @property def running( self ): return self._running @@ -482,13 +495,6 @@ def check_limits( self, runtime=None ): return True return False - def cleanup( self ): - for file in [ getattr( self, a ) for a in self.cleanup_file_attributes if hasattr( self, a ) ]: - try: - os.unlink( file ) - except Exception as e: - log.debug( "(%s/%s) Unable to cleanup %s: %s" % ( self.job_wrapper.get_id_tag(), self.job_id, file, str( e ) ) ) - def register_cleanup_file_attribute( self, attribute ): if attribute not in self.cleanup_file_attributes: self.cleanup_file_attributes.append( attribute )