Stop jobs when all output datasets are deleted via the API.

This commit is contained in:
Nate Coraor
2014-02-19 12:00:33 -06:00
parent 1ba20cc99c
commit 8ecae313d8
3 changed files with 17 additions and 8 deletions
+12
View File
@@ -849,6 +849,18 @@ class UsesHistoryDatasetAssociationMixin:
break
return job
def stop_hda_creating_job( self, hda ):
"""
Stops an HDA's creating job if all the job's other outputs are deleted.
"""
if hda.parent_id is None and len( hda.creating_job_associations ) > 0:
# Mark associated job for deletion
job = hda.creating_job_associations[0].job
if job.state in [ self.app.model.Job.states.QUEUED, self.app.model.Job.states.RUNNING, self.app.model.Job.states.NEW ]:
# Are *all* of the job's other output datasets deleted?
if job.check_if_output_datasets_deleted():
job.mark_deleted( self.app.config.track_jobs_in_database )
self.app.job_manager.job_stop_queue.put( job.id )
class UsesLibraryMixin:
@@ -278,6 +278,8 @@ class HistoryContentsController( BaseAPIController, UsesHistoryDatasetAssociatio
# get_dataset can return a string during an error
if hda and isinstance( hda, trans.model.HistoryDatasetAssociation ):
changed = self.set_hda_from_dict( trans, hda, payload )
if payload.get( 'deleted', False ):
self.stop_hda_creating_job( hda )
except Exception, exception:
log.error( 'Update of history (%s), HDA (%s) failed: %s',
history_id, id, str( exception ), exc_info=True )
@@ -347,6 +349,8 @@ class HistoryContentsController( BaseAPIController, UsesHistoryDatasetAssociatio
trans.sa_session.flush()
rval[ 'purged' ] = True
self.stop_hda_creating_job( hda )
trans.sa_session.flush()
rval[ 'deleted' ] = True
@@ -839,14 +839,7 @@ class DatasetInterface( BaseUIController, UsesAnnotations, UsesHistoryMixin, Use
hda.mark_deleted()
hda.clear_associated_files()
trans.log_event( "Dataset id %s marked as deleted" % str(id) )
if hda.parent_id is None and len( hda.creating_job_associations ) > 0:
# Mark associated job for deletion
job = hda.creating_job_associations[0].job
if job.state in [ self.app.model.Job.states.QUEUED, self.app.model.Job.states.RUNNING, self.app.model.Job.states.NEW ]:
# Are *all* of the job's other output datasets deleted?
if job.check_if_output_datasets_deleted():
job.mark_deleted( self.app.config.track_jobs_in_database )
self.app.job_manager.job_stop_queue.put( job.id )
self.stop_hda_creating_job( hda )
trans.sa_session.flush()
except Exception, e:
msg = 'HDA deletion failed (encoded: %s, decoded: %s)' % ( dataset_id, id )