Fix #658 and #974 - Rollback database on_return of task

This commit is contained in:
Jessica Tallon 2014-12-01 13:39:35 +00:00
parent 1c8f52daee
commit fbb3ee5041
2 changed files with 15 additions and 3 deletions

View File

@ -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.

View File

@ -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)