Clarify why we need database.UserThenDisconnect

This commit is contained in:
Joseph Schorr 2015-02-05 15:00:19 -05:00
parent 555bd293ea
commit bc119aed22

View file

@ -61,16 +61,19 @@ def _sign_sythentic_image(verb, linked_storage_uuid, queue_file):
logger.exception('Exception when signing %s image %s', verb, linked_storage_uuid)
return
with database.UseThenDisconnect(app.config):
try:
derived = model.get_storage_by_uuid(linked_storage_uuid)
except model.InvalidImageException:
return
# Setup the database (since this is a new process) and then disconnect immediately
# once the operation completes.
if not queue_file.raised_exception:
with database.UseThenDisconnect(app.config):
try:
derived = model.get_storage_by_uuid(linked_storage_uuid)
except model.InvalidImageException:
return
signature_entry = model.find_or_create_storage_signature(derived, signer.name)
signature_entry.signature = signature
signature_entry.uploading = False
signature_entry.save()
signature_entry = model.find_or_create_storage_signature(derived, signer.name)
signature_entry.signature = signature
signature_entry.uploading = False
signature_entry.save()
def _write_synthetic_image_to_storage(verb, linked_storage_uuid, linked_locations, queue_file):
@ -89,6 +92,8 @@ def _write_synthetic_image_to_storage(verb, linked_storage_uuid, linked_location
queue_file.close()
if not queue_file.raised_exception:
# Setup the database (since this is a new process) and then disconnect immediately
# once the operation completes.
with database.UseThenDisconnect(app.config):
done_uploading = model.get_storage_by_uuid(linked_storage_uuid)
done_uploading.uploading = False