Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(215)

Side by Side Diff: isolateserver_archive.py

Issue 14455006: Do not retry uploading to blobstore on HTTP 500, regenerate a new url first. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/swarm_client
Patch Set: Rebasef of 14383005 Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | run_isolated.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Archives a set of files to a server.""" 6 """Archives a set of files to a server."""
7 7
8 import binascii 8 import binascii
9 import hashlib 9 import hashlib
10 import logging 10 import logging
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 120
121 Arguments: 121 Arguments:
122 generate_upload_url: The url to get the new upload url from. 122 generate_upload_url: The url to get the new upload url from.
123 data: extra POST data. 123 data: extra POST data.
124 hash_key: sha1 of the uncompressed version of content. 124 hash_key: sha1 of the uncompressed version of content.
125 content: The contents to upload. Must fit in memory for now. 125 content: The contents to upload. Must fit in memory for now.
126 """ 126 """
127 logging.debug('Generating url to directly upload file to blobstore') 127 logging.debug('Generating url to directly upload file to blobstore')
128 assert isinstance(hash_key, str), hash_key 128 assert isinstance(hash_key, str), hash_key
129 assert isinstance(content, str), (hash_key, content) 129 assert isinstance(content, str), (hash_key, content)
130 upload_url = url_open(generate_upload_url, data=data).read() 130 for _ in range(run_isolated.MAX_URL_OPEN_ATTEMPTS):
131 # Retry HTTP 50x here.
132 response = run_isolated.url_open(generate_upload_url, data=data)
133 if not response:
134 raise run_isolated.MappingError(
135 'Unable to connect to server %s' % generate_upload_url)
136 upload_url = response.read()
131 137
132 if not upload_url: 138 # TODO(maruel): Support large files.
133 logging.error('Unable to generate upload url') 139 content_type, body = encode_multipart_formdata(
csharp 2013/04/26 17:51:58 Move this out of the loop
M-A Ruel 2013/04/26 17:56:22 Oops, done.
134 return 140 data, [('content', hash_key, content)])
135 141 # Do not retry this request on HTTP 50x. Regenerate an upload url each time
136 # TODO(maruel): Support large files. 142 # since uploading "consumes" the upload url.
137 content_type, body = encode_multipart_formdata( 143 result = run_isolated.url_open(
138 data, [('content', hash_key, content)]) 144 upload_url, data=body, content_type=content_type, retry_50x=False)
139 return url_open(upload_url, data=body, content_type=content_type) 145 if result:
146 return result.read()
147 raise run_isolated.MappingError(
148 'Unable to connect to server %s' % generate_upload_url)
140 149
141 150
142 class UploadRemote(run_isolated.Remote): 151 class UploadRemote(run_isolated.Remote):
143 def __init__(self, namespace, base_url, token): 152 def __init__(self, namespace, base_url, token):
144 self.namespace = str(namespace) 153 self.namespace = str(namespace)
145 self._token = token 154 self._token = token
146 super(UploadRemote, self).__init__(base_url) 155 super(UploadRemote, self).__init__(base_url)
147 156
148 def get_file_handler(self, base_url): 157 def get_file_handler(self, base_url):
149 base_url = str(base_url) 158 base_url = str(base_url)
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 with run_isolated.Profiler('Archive'): 367 with run_isolated.Profiler('Archive'):
359 return upload_sha1_tree( 368 return upload_sha1_tree(
360 base_url=options.remote, 369 base_url=options.remote,
361 indir=os.getcwd(), 370 indir=os.getcwd(),
362 infiles=infiles, 371 infiles=infiles,
363 namespace=options.namespace) 372 namespace=options.namespace)
364 373
365 374
366 if __name__ == '__main__': 375 if __name__ == '__main__':
367 sys.exit(main(sys.argv[1:])) 376 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « no previous file | run_isolated.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698