Skip to content

Commit

Permalink
Fix problem with cleaning up jobs in local runner.
Browse files Browse the repository at this point in the history
Fixes galaxyproject#3801 (broken in b78287f as part of galaxyproject#3291).
  • Loading branch information
jmchilton committed Mar 22, 2017
1 parent c84b3ba commit a5a3946
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions lib/galaxy/jobs/runners/__init__.py
Expand Up @@ -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()
Expand All @@ -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 ):
"""
Expand All @@ -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
Expand Down Expand Up @@ -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 )
Expand Down

0 comments on commit a5a3946

Please sign in to comment.