Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

writing file in heroku filesystem and reading it with web app

Tags:

heroku

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?

like image 503
jgozal Avatar asked Oct 02 '16 03:10

jgozal


1 Answers

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).

like image 93
Yoni Rabinovitch Avatar answered Nov 06 '22 17:11

Yoni Rabinovitch