Extra debug logging for file uploads

This commit is contained in:
Sybren A. Stüvel 2016-08-24 11:33:02 +02:00
parent d5cf3b8246
commit 9b2a419d9b

View File

@ -683,6 +683,10 @@ def stream_to_gcs(project_id):
else: else:
# Upload the file to GCS. # Upload the file to GCS.
from gcloud.streaming import transfer from gcloud.streaming import transfer
log.debug('Streaming file to GCS bucket; id=%s, fname=%s, size=%i',
file_id, internal_fname, file_size)
# Files larger than this many bytes will be streamed directly from disk, smaller # Files larger than this many bytes will be streamed directly from disk, smaller
# ones will be read into memory and then uploaded. # ones will be read into memory and then uploaded.
transfer.RESUMABLE_UPLOAD_THRESHOLD = 102400 transfer.RESUMABLE_UPLOAD_THRESHOLD = 102400
@ -702,19 +706,24 @@ def stream_to_gcs(project_id):
# Reload the blob to get the file size according to Google. # Reload the blob to get the file size according to Google.
blob.reload() blob.reload()
log.debug('Marking uploaded file id=%s, fname=%s, size=%i as "queued_for_processing"',
file_id, internal_fname, blob.size)
update_file_doc(file_id, update_file_doc(file_id,
status='queued_for_processing', status='queued_for_processing',
file_path=internal_fname, file_path=internal_fname,
length=blob.size, length=blob.size,
content_type=uploaded_file.mimetype) content_type=uploaded_file.mimetype)
log.debug('Processing uploaded file id=%s, fname=%s, size=%i', file_id, internal_fname, blob.size)
process_file(gcs, file_id, local_file) process_file(gcs, file_id, local_file)
# Local processing is done, we can close the local file so it is removed. # Local processing is done, we can close the local file so it is removed.
if local_file is not None: if local_file is not None:
local_file.close() local_file.close()
log.debug('Handled uploaded file id=%s, fname=%s, size=%i', file_id, internal_fname, blob.size) log.debug('Handled uploaded file id=%s, fname=%s, size=%i, status=%i',
file_id, internal_fname, blob.size, status)
# Status is 200 if the file already existed, and 201 if it was newly created. # Status is 200 if the file already existed, and 201 if it was newly created.
# TODO: add a link to a thumbnail in the response. # TODO: add a link to a thumbnail in the response.
@ -791,6 +800,9 @@ def create_file_doc_for_upload(project_id, uploaded_file):
status, file_fields) status, file_fields)
raise wz_exceptions.InternalServerError() raise wz_exceptions.InternalServerError()
log.debug('Created file document %s for uploaded file %s; internal name %s',
file_fields['_id'], uploaded_file.filename, internal_filename)
return file_fields['_id'], internal_filename, status return file_fields['_id'], internal_filename, status