在Heroku文件系统中写入文件并使用Web应用程序阅读 [英] writing file in heroku filesystem and reading it with web app

查看:104
本文介绍了在Heroku文件系统中写入文件并使用Web应用程序阅读的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序中有一个工作进程,每小时运行一次脚本。此脚本将数据写入Web应用程序用来更新其内容的文件系统。我注意到,虽然工作人员成功地运行了这个过程,但数据并没有被更新。这与Heroku的文件系统是只读的事实有关吗?如果是这样,我怎么写这个文件,而不必进入数据库?

解决方案

假设您的web和工作进程实例化你的proc文件中有不同的行,它们运行在不同的Heroku dynos上,每个都有它自己的文件系统。

因此,你的web进程不能访问你的工作进程的文件系统,反之亦然。



此外,即使您在同一个dyno上运行这两个进程(可能但不推荐),仍然无法使用本地dyno文件系统可以可靠地将信息从一个进程传输到另一个进程,因为Heroku dynos可以并且将会 rel=\"nofollow\">至少每24小时大约一次,并且当他们这样做时,在回收消息前您写入本地文件系统的任何文件都可以重复使用。



底线:你不应该也不能使用当地的他roku文件系统用于你正在尝试做的事情。相反,您需要使用某种有状态的支持服务(例如 Heroku Redis ) 。


I have a worker process in my app running a script every hour. This script writes data to the file system which the web app uses to update its contents. I've noticed that although the worker runs the process successfully, the data is not being updated. Is this at all related to the fact that heroku's file system is read only? If so, how can I write this file without having to get into databases?

解决方案

Assuming your web and worker processes are instantiated in separate rows in your procfile, they are running on separate Heroku dynos, each with its own file system.

So, your web process does not have access to your worker process's file system, or vice versa.

Furthermore, even if you ran both processes on the same dyno (which is possible, but NOT recommended), you still could not use the local dyno file system to reliably transfer information from one process to another, since Heroku dynos can and will recycle without prior warning at least once every 24 hours or so, and when they do so any files you wrote to the local file system before the recycle disappear.

Bottom line: You should not and cannot use the local Heroku file system for what you are trying to do. Instead, you need to use some kind of stateful backing service (such as e.g Heroku Redis).

这篇关于在Heroku文件系统中写入文件并使用Web应用程序阅读的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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