gpt4 book ai didi

java - Google Appengine JAVA - 压缩 blobstore 文件会导致保存回 blobstore 时出现错误 202

转载 作者:行者123 更新时间:2023-12-01 04:32:54 27 4
gpt4 key购买 nike

我正在 appengine 中开发一个应用程序,我们希望能够向离线用户提供内容。这意味着我们需要获取所有使用过的 blobstore 文件并为离线用户保存它们。我使用服务器端来执行此操作,以便只执行一次,而不是针对每个最终用户。我正在使用任务队列来运行此进程,因为它很容易超时。假设所有这些代码都作为任务运行。

小型集合工作正常,但较大集合会导致 appengine 错误 202,并且会一次又一次重新启动任务。这是来自 Writing Zip Files to GAE Blobstore 组合的示例代码并遵循 Google Appengine JAVA - Zip lots of images saving in Blobstore 对于大型 zip 文件的建议根据需要重新打开 channel 。另引用AppEngine Error Code 202 - Task Queue作为错误。

//Set up the zip file that will be saved to the blobstore
AppEngineFile assetFile = fileService.createNewBlobFile("application/zip", assetsZipName);
FileWriteChannel writeChannel = fileService.openWriteChannel(assetFile, true);
ZipOutputStream assetsZip = new ZipOutputStream(new BufferedOutputStream(Channels.newOutputStream(writeChannel)));

HashSet<String> blobsEntries = getAllBlobEntries(); //gets blobs that I need
saveBlobAssetsToZip(blobsEntries);

writeChannel.closeFinally();

......

private void saveBlobAssetsToZip(blobsEntries) throws IOException  {        
for (String blobId : blobsEntries) {

/*gets the blobstote key that will result in the blobstore entry - ignore the bsmd as
that is internal to our wrapper for blobstore.*/

BlobKey blobKey = new BlobKey(bsmd.getBlobId());

//gets the blob file as a byte array
byte[] blobData = blobstoreService.fetchData(blobKey, 0, BlobstoreService.MAX_BLOB_FETCH_SIZE-1);
String extension = type of file saved from our metadata (ie .jpg, .png, .pfd)

assetsZip.putNextEntry(new ZipEntry(blobId + "." + extension));

assetsZip.write(blobData);
assetsZip.closeEntry();
assetsZip.flush();

/*I have found that if I don't close the channel and reopen it, I can get a IO exception
because the files in the blobstore are too large, thus the write a file and then close and reopen*/

assetsZip.close();
writeChannel.close();
String assetsPath = assetFile.getFullPath();
assetFile = new AppEngineFile(assetsPath);
writeChannel = fileService.openWriteChannel(assetFile, true);
assetsZip = new ZipOutputStream(new BufferedOutputStream(Channels.newOutputStream(writeChannel)));

}
}

让它在 appengine 上运行的正确方法是什么?同样,小项目工作正常并且 zip 保存,但具有更多 blob 文件的较大项目会导致此错误。

最佳答案

我敢打赌该实例内存不足。你在使用appstats吗?它会消耗大量内存。如果这不起作用,您可能需要增加实例大小。

关于java - Google Appengine JAVA - 压缩 blobstore 文件会导致保存回 blobstore 时出现错误 202,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17755514/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com