Python cloudstorage.RetryParams() Examples
The following are 8
code examples of cloudstorage.RetryParams().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
cloudstorage
, or try the search function
.
Example #1
Source File: base_handler.py From locality-sensitive-hashing with MIT License | 6 votes |
def __init__(self, *args, **kwargs): # webapp framework invokes initialize after __init__. # webapp2 framework invokes initialize within __init__. # Python27 runtime swap webapp with webapp2 underneath us. # Since initialize will conditionally change this field, # it needs to be set before calling super's __init__. self._preprocess_success = False super(TaskQueueHandler, self).__init__(*args, **kwargs) if cloudstorage: cloudstorage.set_default_retry_params( cloudstorage.RetryParams( min_retries=5, max_retries=10, urlfetch_timeout=parameters._GCS_URLFETCH_TIMEOUT_SEC, save_access_token=True, _user_agent=self._DEFAULT_USER_AGENT))
Example #2
Source File: storage.py From isthislegit with BSD 3-Clause "New" or "Revised" License | 6 votes |
def upload(self, attachment, content): ''' Uploads a file to the default cloud storage bucket Args: attachment - The models.Attachment metadata for the file content - The file content ''' filename = '/{}/{}'.format(self.bucket_name, attachment.stored_filename) write_retry_params = gcs.RetryParams(backoff_factor=1.1) gcs_file = gcs.open( filename, 'w', content_type=attachment.mime_type, retry_params=write_retry_params) gcs_file.write(content) gcs_file.close()
Example #3
Source File: main.py From python-docs-samples with Apache License 2.0 | 6 votes |
def create_file(self, filename): """Create a file.""" self.response.write('Creating file {}\n'.format(filename)) # The retry_params specified in the open call will override the default # retry params for this particular file handle. write_retry_params = cloudstorage.RetryParams(backoff_factor=1.1) with cloudstorage.open( filename, 'w', content_type='text/plain', options={ 'x-goog-meta-foo': 'foo', 'x-goog-meta-bar': 'bar'}, retry_params=write_retry_params) as cloudstorage_file: cloudstorage_file.write('abcde\n') cloudstorage_file.write('f'*1024*4 + '\n') self.tmp_filenames_to_clean_up.append(filename) # [END write] # [START read]
Example #4
Source File: base_handler.py From appengine-mapreduce with Apache License 2.0 | 6 votes |
def __init__(self, *args, **kwargs): # webapp framework invokes initialize after __init__. # webapp2 framework invokes initialize within __init__. # Python27 runtime swap webapp with webapp2 underneath us. # Since initialize will conditionally change this field, # it needs to be set before calling super's __init__. self._preprocess_success = False super(TaskQueueHandler, self).__init__(*args, **kwargs) if cloudstorage: cloudstorage.set_default_retry_params( cloudstorage.RetryParams( min_retries=5, max_retries=10, urlfetch_timeout=parameters._GCS_URLFETCH_TIMEOUT_SEC, save_access_token=True, _user_agent=self._DEFAULT_USER_AGENT))
Example #5
Source File: gcs.py From luci-py with Apache License 2.0 | 5 votes |
def _make_retry_params(): """RetryParams structure configured to store access token in Datastore.""" # Note that 'cloudstorage.set_default_retry_params' function stores retry # params in per-request thread local storage, which means it needs to be # called for each request. Since we are wrapping all cloudstorage library # calls anyway, it's more convenient just to pass RetryParams explicitly, # instead of making it a default for request with 'set_default_retry_params'. return cloudstorage.RetryParams(save_access_token=True)
Example #6
Source File: main.py From appengine-photoalbum-example with Apache License 2.0 | 5 votes |
def post(): form = PhotoForm(CombinedMultiDict((request.files, request.form))) if request.method == 'POST' and form.validate(): filename = '%s.%s' % (str(uuid.uuid4()), secure_filename(form.input_photo.data.filename)) content_type = content_types[filename.split('.')[-1]] write_retry_params = gcs.RetryParams(backoff_factor=1.1) gcs_file = gcs.open('/%s/%s' % (bucket_name, filename), 'w', retry_params=write_retry_params, content_type=content_type, options={'x-goog-acl': 'authenticated-read'}) for _ in form.input_photo.data.stream: gcs_file.write(_) gcs_file.close() labels = get_labels(filename) tags = [translate_text(label.description) for label in labels] entity = Photo(id=filename, tags=tags, parent=ndb.Key('User', 'default')) entity.put() for tag in tags: entity = ndb.Key('User', 'default', 'Tags', tag).get() if entity: entity.count += 1 else: entity = Tags(count=1, id=tag, parent=ndb.Key('User', 'default')) entity.put() return render_template('post.html', storage_path=storage_path, filename=filename, tags=tags) else: return redirect(url_for('photos'))
Example #7
Source File: storage.py From GAEPyPI with GNU General Public License v3.0 | 5 votes |
def write(self, path, content): write_retry_params = gcs.RetryParams(backoff_factor=1.1) gcs_file = gcs.open(path, 'w', options={'x-goog-acl': self.acl}, retry_params=write_retry_params) gcs_file.write(content) gcs_file.close()
Example #8
Source File: shuffler.py From appengine-mapreduce with Apache License 2.0 | 5 votes |
def delete_file_or_list(self, filename_or_list): if isinstance(filename_or_list, list): for filename in filename_or_list: self.delete_file_or_list(filename) else: filename = filename_or_list retry_params = cloudstorage.RetryParams(min_retries=self._MIN_RETRIES, max_retries=self._MAX_RETRIES) # pylint: disable=bare-except try: cloudstorage.delete(filename, retry_params) except: pass