Skip to content

Commit

Permalink
Merge pull request #984 from parklab/scottx611x/galaxy_deletion
Browse files Browse the repository at this point in the history
Scottx611x/galaxy deletion
  • Loading branch information
scottx611x committed Mar 24, 2016
2 parents 8cc8586 + 010c6b7 commit d9d6d81
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 19 deletions.
5 changes: 5 additions & 0 deletions refinery/config/config.json.erb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@
"REFINERY_EXTERNAL_AUTH": false,
"REFINERY_EXTERNAL_AUTH_MESSAGE": "",
"REFINERY_FILE_SOURCE_MAP": {},
"REFINERY_GALAXY_ANALYSIS_CLEANUP": {
"ALWAYS": "always",
"ON_SUCCESS": "on_success",
"NEVER": "never"
},
"REFINERY_GOOGLE_ANALYTICS_ID": "",
"REFINERY_INNER_NAVBAR_HEIGHT": 20,
"REFINERY_MAIN_LOGO": "",
Expand Down
5 changes: 5 additions & 0 deletions refinery/config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,11 @@ def get_setting(name, settings=local_settings):
# Display REFINERY_BANNER to anonymous users only
REFINERY_BANNER_ANONYMOUS_ONLY = get_setting("REFINERY_BANNER_ANONYMOUS_ONLY")

# Setting to allow users to select if they want to keep workflows,
# histories, and libraries in Galaxy or not.
# Deletion options are ALWAYS, ON_SUCCESS, and NEVER
REFINERY_GALAXY_ANALYSIS_CLEANUP = get_setting(
"REFINERY_GALAXY_ANALYSIS_CLEANUP")["ON_SUCCESS"]
# Subject and message body of the welcome email sent to new users
REFINERY_WELCOME_EMAIL_SUBJECT = get_setting("REFINERY_WELCOME_EMAIL_SUBJECT")
REFINERY_WELCOME_EMAIL_MESSAGE = get_setting("REFINERY_WELCOME_EMAIL_MESSAGE")
Expand Down
48 changes: 29 additions & 19 deletions refinery/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1061,28 +1061,38 @@ def galaxy_progress(self):
return history['percent_complete']

def galaxy_cleanup(self):
"""Delete library, workflow and history from Galaxy if they exist"""
connection = self.galaxy_connection()
error_msg = "Error deleting Galaxy %s for analysis '%s': %s"
"""Determine when/if Galaxy libraries, workflows and histories are
to be deleted based on the value of
global setting: REFINERY_GALAXY_ANALYSIS_CLEANUP"""

if self.library_id:
try:
connection.libraries.delete_library(self.library_id)
except galaxy.client.ConnectionError as e:
logger.error(error_msg, 'library', self.name, e.message)
cleanup = settings.REFINERY_GALAXY_ANALYSIS_CLEANUP

if self.workflow_galaxy_id:
try:
connection.workflows.delete_workflow(self.workflow_galaxy_id)
except galaxy.client.ConnectionError as e:
logger.error(error_msg, 'workflow', self.name, e.message)
if cleanup == 'always' or cleanup == 'on_success' and \
self.get_status() == self.SUCCESS_STATUS:

if self.history_id:
try:
connection.histories.delete_history(
self.history_id, purge=True)
except galaxy.client.ConnectionError as e:
logger.error(error_msg, 'history', self.name, e.message)
connection = self.galaxy_connection()
error_msg = "Error deleting Galaxy %s for analysis '%s': %s"

# Delete Galaxy libraries, workflows and histories
if self.library_id:
try:
connection.libraries.delete_library(self.library_id)
except galaxy.client.ConnectionError as e:
logger.error(error_msg, 'library', self.name, e.message)

if self.workflow_galaxy_id:
try:
connection.workflows.delete_workflow(
self.workflow_galaxy_id)
except galaxy.client.ConnectionError as e:
logger.error(error_msg, 'workflow', self.name, e.message)

if self.history_id:
try:
connection.histories.delete_history(self.history_id,
purge=True)
except galaxy.client.ConnectionError as e:
logger.error(error_msg, 'history', self.name, e.message)

def cancel(self):
"""Mark analysis as cancelled"""
Expand Down

0 comments on commit d9d6d81

Please sign in to comment.