From: Jessica Tallon Date: Mon, 1 Dec 2014 13:39:35 +0000 (+0000) Subject: Fix #658 and #974 - Rollback database on_return of task X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=fbb3ee504168cd4ceb258bf98658c1bc32d8cafd;p=mediagoblin.git Fix #658 and #974 - Rollback database on_return of task --- diff --git a/mediagoblin/config_spec.ini b/mediagoblin/config_spec.ini index dade8420..f769e4eb 100644 --- a/mediagoblin/config_spec.ini +++ b/mediagoblin/config_spec.ini @@ -113,9 +113,7 @@ user_privilege_scheme = string(default="uploader,commenter,reporter") # Frequency garbage collection will run (setting to 0 or false to disable) # Setting units are minutes. -## NOTE: This is temporarily disabled, but we want to set it back: -## garbage_collection = integer(default=60) -garbage_collection = integer(default=0) +garbage_collection = integer(default=60) [jinja2] # Jinja2 supports more directives than the minimum required by mediagoblin. diff --git a/mediagoblin/processing/task.py b/mediagoblin/processing/task.py index 1a21c6d2..0c254767 100644 --- a/mediagoblin/processing/task.py +++ b/mediagoblin/processing/task.py @@ -155,5 +155,19 @@ class ProcessMedia(celery.Task): entry = mgg.database.MediaEntry.query.filter_by(id=entry_id).first() json_processing_callback(entry) + mgg.database.reset_after_request() + + def after_return(self, *args, **kwargs): + """ + This is called after the task has returned, we should clean up. + + We need to rollback the database to prevent ProgrammingError exceptions + from being raised. + """ + # In eager mode we get DetachedInstanceError, we do rollback on_failure + # to deal with that case though when in eager mode. + if not celery.app.default_app.conf['CELERY_ALWAYS_EAGER']: + mgg.database.reset_after_request() + tasks.register(ProcessMedia)