diff options
author | Vilem Duha <vilem.duha@gmail.com> | 2019-05-22 23:08:18 +0300 |
---|---|---|
committer | Vilem Duha <vilem.duha@gmail.com> | 2019-05-23 15:47:17 +0300 |
commit | 87ae620998e7405df66c912250d02e4f954b0077 (patch) | |
tree | 8d2b09fe47b1bd8f63241071aea53a1e5a8866c8 /blenderkit/upload_bg.py | |
parent | 464dd1a50b3a17bd8e9b6b1f7ec4bc0bc27e7ed5 (diff) |
BlenderKit: Check better that upload failed.
Diffstat (limited to 'blenderkit/upload_bg.py')
-rw-r--r-- | blenderkit/upload_bg.py | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/blenderkit/upload_bg.py b/blenderkit/upload_bg.py index 1fa6f6fb..a1cfaf11 100644 --- a/blenderkit/upload_bg.py +++ b/blenderkit/upload_bg.py @@ -68,6 +68,7 @@ def upload_files(filepath, upload_data, files): headers = utils.get_headers(upload_data['token']) version_id = upload_data['id'] + uploaded_all = True for f in files: bg_blender.progress('uploading %s' % f['type']) upload_info = { @@ -92,7 +93,7 @@ def upload_files(filepath, upload_data, files): # file gets uploaded here: uploaded = False # s3 upload is now the only option - for a in range(0, 20): + for a in range(0, 5): if not uploaded: try: upload_response = requests.put(upload['s3UploadUrl'], @@ -102,7 +103,7 @@ def upload_files(filepath, upload_data, files): if upload_response.status_code == 200: uploaded = True else: - bg_blender.progress('Upload failed, retry.') + bg_blender.progress(f'Upload failed, retry. {a}') except Exception as e: bg_blender.progress('Upload %s failed, retrying' % f['type']) time.sleep(1) @@ -110,10 +111,11 @@ def upload_files(filepath, upload_data, files): # confirm single file upload to bkit server upload_done_url = paths.get_api_url() + 'uploads_s3/' + upload['id'] + '/upload-file/' upload_response = requests.post(upload_done_url, headers=headers, verify=True) - + if not uploaded: + uploaded_all = False bg_blender.progress('finished uploading') - return {'FINISHED'} + return uploaded_all if __name__ == "__main__": @@ -180,23 +182,25 @@ if __name__ == "__main__": bg_blender.progress('uploading') - upload_files(fpath, upload_data, files) - - # mark on server as uploaded - confirm_data = { - "verificationStatus": "uploaded" - } + uploaded = upload_files(fpath, upload_data, files) - url = paths.get_api_url() + 'assets/' + if uploaded: + # mark on server as uploaded + confirm_data = { + "verificationStatus": "uploaded" + } - headers = utils.get_headers(upload_data['token']) + url = paths.get_api_url() + 'assets/' - url += upload_data["id"] + '/' + headers = utils.get_headers(upload_data['token']) - r = requests.patch(url, json=confirm_data, headers=headers, verify=True) # files = files, + url += upload_data["id"] + '/' - bg_blender.progress('upload finished successfully') + r = requests.patch(url, json=confirm_data, headers=headers, verify=True) # files = files, + bg_blender.progress('upload finished successfully') + else: + bg_blender.progress('upload failed.') except Exception as e: print(e) |