python - How to write to cloudstorage using task chaining, The blobstore Files API did a nice job -



python - How to write to cloudstorage using task chaining, The blobstore Files API did a nice job -

using blobstore file api, write very big blobfiles:

create blobfile read info datastore , write (append) blobstore file pass datastore page cursor , blobstore file (next) task ....use other tasks same purpose and finalize blobstore file

now gae gcs client cannot append , finalize. how write big files gcs without compose. compose not part of gcs client. files api still works fine, has been deprecated.

below blobstore solution using task chaining:

class blobdata(webapp2.requesthandler): def post(self): page = int(self.request.get('page', default_value='0')) info = data.get_data(.....) blob_file = self.request.get('blobfile', default_value='none') if blob_file == 'none': file_name = files.blobstore.create(mime_type='text/...', _blobinfo_uploaded_filename='data....txt') else: data.with_cursor(self.request.get('cursor')) count = 0 # page lines counter files.open(blob_file, 'a') f: each in data.fetch(page): f.write(each) count += 1 if count >= page: cursor = data.cursor() taskqueue.add(url='/blobdata', queue_name='blobdata', countdown=10, method='post', params={'page': page, 'cursor': cursor, 'blobfile': blob_file}, headers={'x-appengine-failfast': 'true'}) else: # no info left files.finalize(blob_file)

in java client, can serialize reading channel (the equivalent of buffer in python client), , pass task go on writing in same file. see the java doc more info :

a readable byte channel reading info google cloud storage. implementations of class may buffer info internally cut down remote calls.

this class serializable, allows reading part of file, serializing gcsinputchannel deserializing it, , continuing read same file same position.

i not know if buffers returned python gcs client serializable, did not find info in doc, might worth checking.

if that's not possible, utilize composition. not worry fact composition not available in gcs client, can utilize standard cloud storage api library app engine. api documentation has compose illustration in python here. looks :

composite_object_resource = { 'contenttype': 'text/plain', # required 'contentlanguage': 'en', 'metadata': {'my-key': 'my-value'}, } compose_req_body = { 'sourceobjects': [ {'name': source_object_name_1, 'objectpreconditions': {'ifgenerationmatch': source_generation_1}}, {'name': source_object_name_2, 'objectpreconditions': {'ifgenerationmatch': source_generation_2}}], 'destination': composite_object_resource } req = client.objects().compose( destinationbucket=bucket_name, destinationobject=composite_object_name, body=compose_req_body) resp = req.execute() print json.dumps(resp, indent=2)

python google-app-engine python-2.7 google-cloud-storage blobstore

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -