在Heroku上保存文件更改

在Heroku上保存文件更改

本文介绍了在Heroku上保存文件更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在heroku上有一个node.js应用程序,可以检查电子邮件,然后如果电子邮件符合certian条件,它将进行回复.

I hava a node.js app on heroku thath checks for emails and then if the email match certian cliteria it would reply.

因为heroku经常重新启动dyno,所以我制作了一个文件来保存我已经作弊的电子邮件的ID(一小数组)(因此它不会对同一封电子邮件重复两次),但是我很傻, heroku也会重新启动该文件,因此不会保存我所做的任何更改.

Because heroku restarts the dyno every so often I made a file that saves the ids of the emails (a small array) I've already cheaked (so it doesn't reply twice to the same email), but silly me, heroku restarts that file too, so no changes I made will be save.

是否可以保存应用对文件所做的更改?如果您知道做我想做的更好的方法?

Is there a way to save the file changes the app makes to it?If you know of a better way of to do what I want to?

推荐答案

Heroku强制执行此行为(本地文件删除内容),因为这是最佳做法.在本地写入文件不能很好地扩展,并且当您在同一VM上有多个进程都执行文件I/O操作时,可能会导致一些奇怪的极端情况.

Heroku enforces this behavior (the local file deletion stuff) because it is a best practice. Writing files locally doesn't scale well, and can lead to some odd edge-case behaviors when you have multiple processes on the same VM all performing file I/O operations.

您应该使用的是数据库,缓存(例如Redis),甚至只是将文件直接写入文件存储服务,例如 Amazon S3 .

What you should use instead is either a database, a cache (like Redis), or even just write your file directly to a file storage service like Amazon S3.

我意识到这听起来很烦人,即使对于像您在此处这样的简单用例,您也必须做这些额外的事情-但Heroku的平台旨在执行最佳实践,以帮助人们构建可扩展的,可靠的软件.

I realize it sounds annoying that you have to do these extra things even for a simple use case like what you're doing here -- but Heroku's platform is geared around enforcing best practices to help people build scalable, reliable software.

如果您正在寻找一种无需额外麻烦即可完成此类工作的方法,则可能需要考虑从另一家公司购买小型VPS服务器,从而可以直接控制流程,磁盘等.

If you're looking for a way to do stuff like this without the extra hassle, you might want to consider just purchasing a small VPS server from another company where you can have direct control over processes, disk, etc.

这篇关于在Heroku上保存文件更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 23:20