def _cleanup_uploads(self): """ Performs cleanup on the blobupload table. """ logger.debug("Performing blob upload cleanup") while True: # Find all blob uploads older than the threshold (typically a week) and delete them. with UseThenDisconnect(app.config): stale_upload = model.get_stale_blob_upload(DELETION_DATE_THRESHOLD) if stale_upload is None: logger.debug("No additional stale blob uploads found") return # Remove the stale upload from storage. logger.debug("Removing stale blob upload %s", stale_upload.uuid) assert stale_upload.created <= (datetime.utcnow() - DELETION_DATE_THRESHOLD) try: storage.cancel_chunked_upload( [stale_upload.location_name], stale_upload.uuid, stale_upload.storage_metadata ) except Exception as ex: logger.debug( "Got error when trying to cancel chunked upload %s: %s", stale_upload.uuid, ex.message, ) # Delete the stale upload's row. with UseThenDisconnect(app.config): model.delete_blob_upload(stale_upload) logger.debug("Removed stale blob upload %s", stale_upload.uuid)
def _cleanup_uploads(self): """ Performs garbage collection on the blobupload table. """ while True: # Find all blob uploads older than the threshold (typically a week) and delete them. with UseThenDisconnect(app.config): stale_upload = model.get_stale_blob_upload(DELETION_DATE_THRESHOLD) if stale_upload is None: logger.debug('No additional stale blob uploads found') return # Remove the stale upload from storage. logger.debug('Removing stale blob upload %s', stale_upload.uuid) try: storage.cancel_chunked_upload([stale_upload.location_name], stale_upload.uuid, stale_upload.storage_metadata) except Exception as ex: logger.debug('Got error when trying to cancel chunked upload %s: %s', stale_upload.uuid, ex.message) # Delete the stale upload's row. with UseThenDisconnect(app.config): model.delete_blob_upload(stale_upload) logger.debug('Removed stale blob upload %s', stale_upload.uuid)