Heroku dynos不共享文件系统 [英] Heroku dynos not sharing the file system

查看:65
本文介绍了Heroku dynos不共享文件系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的heroku Web应用程序具有从S3下载图像的功能.它是这样的:

My heroku web app has a feature to download images from S3. It works like this:

  1. 有一个端点(A)请求下载一组图像,并返回一个任务ID.
  2. 这些图像由A下载到我的应用程序的tmp Heroku文件夹中.下载完所有图像后,便会创建一个zip文件.
  3. 虽然图像仍可以下载,但Web客户端从点1开始调用另一个具有任务ID的端点(B).此第二个端点检查已下载了多少图像以返回进度百分比.创建zip后,它会返回" zip文件并下载图像.
  1. There is one endpoint (A) to request downloading an array of images, that returns a task id.
  2. Those images are downloaded by A to the tmp Heroku folder of my app. And when all images are downloaded, a zip file is created.
  3. While images can still be downloading, the web client calls another endpoint (B) with the task id from point 1. This second endpoint checks how many images are already downloaded to return a progress percentage. When the zip is already created it "returns" the zip file and the images are downloaded.

这种方法在Heroku中使用1个dyno效果很好.不幸的是,在将比例缩放到2 dynos之后,我们意识到它不再起作用了.原因是Heroku中的dynos不共享相同的文件系统,并且端点A和B由不同的dynos管理.因此,端点B中的dyno找不到任何文件.

This approach worked fine in Heroku with 1 dyno. Unfortunately, after scaling to 2 dynos, we have realised that it doesn't work anymore. The reason is that dynos in Heroku doesn't share the same file system, and endpoint A and B are managed by different dynos. Therefore, the dyno in endpoint B doesn't find any file.

是否有一种简单的方法可以使我的方法与多个测功一起使用?

Is there an easy way to make my approach work with multiple dynos?

如果没有,我应该如何实现所描述的功能? (从S3中以zip文件下载多个图像)

If not, how should I implement the feature described? (downloading multiple images from S3 in a zip file)

推荐答案

您可以创建第二个S3存储桶,并在完成下载后将zip文件推送到第二个S3存储桶.然后,您可以重定向客户端以直接从S3下载zip文件.

You could create a second S3 bucket and push the zip file to the second S3 bucket once it's done downloading. Then you can redirect the client to download the zip file directly from S3.

然后设置一个定期运行的进程,以清除该S3存储桶中的旧文件.

Then setup a process to run periodically to clean out anything old in that S3 bucket.

这篇关于Heroku dynos不共享文件系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆