diff --git a/lib/galaxy/web/base/controller.py b/lib/galaxy/web/base/controller.py index 29553a495af..5fbcb2ff16a 100644 --- a/lib/galaxy/web/base/controller.py +++ b/lib/galaxy/web/base/controller.py @@ -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: diff --git a/lib/galaxy/webapps/galaxy/api/history_contents.py b/lib/galaxy/webapps/galaxy/api/history_contents.py index 733cb1f624a..96ef505b741 100644 --- a/lib/galaxy/webapps/galaxy/api/history_contents.py +++ b/lib/galaxy/webapps/galaxy/api/history_contents.py @@ -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 diff --git a/lib/galaxy/webapps/galaxy/controllers/dataset.py b/lib/galaxy/webapps/galaxy/controllers/dataset.py index 448bbd02d9f..4c666b5cc05 100644 --- a/lib/galaxy/webapps/galaxy/controllers/dataset.py +++ b/lib/galaxy/webapps/galaxy/controllers/dataset.py @@ -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 )